home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / lang / lisp / stk-3.002 / stk-3 / STk-3.1 / Doc / Extension / Extending.tex < prev    next >
LaTeX Document  |  1996-07-21  |  43.7 KB

open in: MacOS 8.1     |     Win98     |     DOS

view JSON data     |     view as text

This file was processed as: LaTeX Document (document/latex).

You can browse this item here: Extending.tex

ConfidenceProgramDetectionMatch TypeSupport
100% dexvert LaTeX Document (document/latex) magic Supported
1% dexvert Corel 10 Texture (image/corel10Texture) ext Unsupported
1% dexvert Croteam texture file (image/croteamTextureFile) ext Unsupported
1% dexvert Text File (text/txt) fallback Supported
100% file LaTeX 2e document text default
99% file LaTeX document text default
98% file C source text default
97% file C source, ASCII text default
100% TrID LaTeX 2e document (with rem) default
100% checkBytes Printable ASCII default
100% perlTextCheck Likely Text (Perl) default
100% siegfried fmt/280 LaTeX (Master document) default
100% detectItEasy Format: plain text[LF] default (weak)
100% xdgMime text/x-matlab default (weak)



hex view
+--------+-------------------------+-------------------------+--------+--------+
|00000000| 25 0a 25 20 41 20 6e 6f | 74 65 20 6f 6e 20 68 6f |%.% A no|te on ho|
|00000010| 77 20 74 6f 20 65 78 74 | 65 6e 64 20 74 68 65 20 |w to ext|end the |
|00000020| 53 54 6b 20 69 6e 74 65 | 72 70 72 65 74 65 72 0a |STk inte|rpreter.|
|00000030| 25 0a 25 20 43 6f 70 79 | 72 69 67 68 74 20 28 43 |%.% Copy|right (C|
|00000040| 29 20 31 39 39 33 2c 31 | 39 39 34 2c 31 39 39 35 |) 1993,1|994,1995|
|00000050| 20 45 72 69 63 6b 20 47 | 61 6c 6c 65 73 69 6f 20 | Erick G|allesio |
|00000060| 2d 20 49 33 53 2d 43 4e | 52 53 2f 45 53 53 49 20 |- I3S-CN|RS/ESSI |
|00000070| 3c 65 67 40 75 6e 69 63 | 65 2e 66 72 3e 0a 25 20 |<eg@unic|e.fr>.% |
|00000080| 0a 25 0a 25 20 50 65 72 | 6d 69 73 73 69 6f 6e 20 |.%.% Per|mission |
|00000090| 74 6f 20 75 73 65 2c 20 | 63 6f 70 79 2c 20 61 6e |to use, |copy, an|
|000000a0| 64 2f 6f 72 20 64 69 73 | 74 72 69 62 75 74 65 20 |d/or dis|tribute |
|000000b0| 74 68 69 73 20 73 6f 66 | 74 77 61 72 65 20 61 6e |this sof|tware an|
|000000c0| 64 20 69 74 73 0a 25 20 | 64 6f 63 75 6d 65 6e 74 |d its.% |document|
|000000d0| 61 74 69 6f 6e 20 66 6f | 72 20 61 6e 79 20 70 75 |ation fo|r any pu|
|000000e0| 72 70 6f 73 65 20 61 6e | 64 20 77 69 74 68 6f 75 |rpose an|d withou|
|000000f0| 74 20 66 65 65 20 69 73 | 20 68 65 72 65 62 79 20 |t fee is| hereby |
|00000100| 67 72 61 6e 74 65 64 2c | 20 70 72 6f 76 69 64 65 |granted,| provide|
|00000110| 64 0a 25 20 74 68 61 74 | 20 62 6f 74 68 20 74 68 |d.% that| both th|
|00000120| 65 20 61 62 6f 76 65 20 | 63 6f 70 79 72 69 67 68 |e above |copyrigh|
|00000130| 74 20 6e 6f 74 69 63 65 | 20 61 6e 64 20 74 68 69 |t notice| and thi|
|00000140| 73 20 70 65 72 6d 69 73 | 73 69 6f 6e 20 6e 6f 74 |s permis|sion not|
|00000150| 69 63 65 20 61 70 70 65 | 61 72 20 69 6e 0a 25 20 |ice appe|ar in.% |
|00000160| 61 6c 6c 20 63 6f 70 69 | 65 73 20 61 6e 64 20 64 |all copi|es and d|
|00000170| 65 72 69 76 65 64 20 77 | 6f 72 6b 73 2e 20 20 46 |erived w|orks. F|
|00000180| 65 65 73 20 66 6f 72 20 | 64 69 73 74 72 69 62 75 |ees for |distribu|
|00000190| 74 69 6f 6e 20 6f 72 20 | 75 73 65 20 6f 66 20 74 |tion or |use of t|
|000001a0| 68 69 73 0a 25 20 73 6f | 66 74 77 61 72 65 20 6f |his.% so|ftware o|
|000001b0| 72 20 64 65 72 69 76 65 | 64 20 77 6f 72 6b 73 20 |r derive|d works |
|000001c0| 6d 61 79 20 6f 6e 6c 79 | 20 62 65 20 63 68 61 72 |may only| be char|
|000001d0| 67 65 64 20 77 69 74 68 | 20 65 78 70 72 65 73 73 |ged with| express|
|000001e0| 20 77 72 69 74 74 65 6e | 0a 25 20 70 65 72 6d 69 | written|.% permi|
|000001f0| 73 73 69 6f 6e 20 6f 66 | 20 74 68 65 20 63 6f 70 |ssion of| the cop|
|00000200| 79 72 69 67 68 74 20 68 | 6f 6c 64 65 72 2e 20 20 |yright h|older. |
|00000210| 0a 25 20 54 68 69 73 20 | 73 6f 66 74 77 61 72 65 |.% This |software|
|00000220| 20 69 73 20 70 72 6f 76 | 69 64 65 64 20 60 60 61 | is prov|ided ``a|
|00000230| 73 20 69 73 27 27 20 77 | 69 74 68 6f 75 74 20 65 |s is'' w|ithout e|
|00000240| 78 70 72 65 73 73 20 6f | 72 20 69 6d 70 6c 69 65 |xpress o|r implie|
|00000250| 64 20 77 61 72 72 61 6e | 74 79 2e 0a 25 0a 25 20 |d warran|ty..%.% |
|00000260| 20 20 20 20 20 20 20 20 | 20 20 41 75 74 68 6f 72 | | Author|
|00000270| 3a 20 45 72 69 63 6b 20 | 47 61 6c 6c 65 73 69 6f |: Erick |Gallesio|
|00000280| 20 5b 65 67 40 75 6e 69 | 63 65 2e 66 72 5d 0a 25 | [eg@uni|ce.fr].%|
|00000290| 20 20 20 20 43 72 65 61 | 74 69 6f 6e 20 64 61 74 | Crea|tion dat|
|000002a0| 65 3a 20 20 69 6e 20 31 | 39 39 33 0a 25 20 4c 61 |e: in 1|993.% La|
|000002b0| 73 74 20 66 69 6c 65 20 | 75 70 64 61 74 65 3a 20 |st file |update: |
|000002c0| 32 31 2d 4a 75 6c 2d 31 | 39 39 36 20 31 39 3a 34 |21-Jul-1|996 19:4|
|000002d0| 37 0a 25 0a 0a 5c 64 6f | 63 75 6d 65 6e 74 63 6c |7.%..\do|cumentcl|
|000002e0| 61 73 73 5b 31 30 70 74 | 5d 7b 61 72 74 69 63 6c |ass[10pt|]{articl|
|000002f0| 65 7d 0a 5c 75 73 65 70 | 61 63 6b 61 67 65 7b 61 |e}.\usep|ackage{a|
|00000300| 34 77 69 64 65 7d 0a 5c | 75 73 65 70 61 63 6b 61 |4wide}.\|usepacka|
|00000310| 67 65 7b 66 61 6e 63 79 | 68 65 61 64 69 6e 67 73 |ge{fancy|headings|
|00000320| 7d 0a 5c 75 73 65 70 61 | 63 6b 61 67 65 7b 66 61 |}.\usepa|ckage{fa|
|00000330| 6e 63 79 62 6f 78 7d 0a | 5c 75 73 65 70 61 63 6b |ncybox}.|\usepack|
|00000340| 61 67 65 7b 65 67 2d 63 | 6f 6d 6d 61 6e 64 73 7d |age{eg-c|ommands}|
|00000350| 0a 0a 5c 70 61 67 65 73 | 74 79 6c 65 7b 66 61 6e |..\pages|tyle{fan|
|00000360| 63 79 70 6c 61 69 6e 7d | 0a 5c 6d 61 6b 65 69 6e |cyplain}|.\makein|
|00000370| 64 65 78 5c 70 61 72 69 | 6e 64 65 6e 74 30 70 74 |dex\pari|ndent0pt|
|00000380| 5c 70 61 72 73 6b 69 70 | 32 6d 6d 0a 5c 62 65 67 |\parskip|2mm.\beg|
|00000390| 69 6e 7b 64 6f 63 75 6d | 65 6e 74 7d 0a 5c 62 69 |in{docum|ent}.\bi|
|000003a0| 62 6c 69 6f 67 72 61 70 | 68 79 73 74 79 6c 65 7b |bliograp|hystyle{|
|000003b0| 70 6c 61 69 6e 7d 0a 0a | 5c 74 69 74 6c 65 7b 45 |plain}..|\title{E|
|000003c0| 78 74 65 6e 64 69 6e 67 | 20 74 68 65 20 53 54 7b |xtending| the ST{|
|000003d0| 5c 6c 61 72 67 65 5c 62 | 66 7b 4b 7d 7d 20 69 6e |\large\b|f{K}} in|
|000003e0| 74 65 72 70 72 65 74 65 | 72 7d 0a 5c 61 75 74 68 |terprete|r}.\auth|
|000003f0| 6f 72 7b 45 72 69 63 6b | 20 47 61 6c 6c 65 73 69 |or{Erick| Gallesi|
|00000400| 6f 20 5c 5c 0a 55 6e 69 | 76 65 72 73 69 74 5c 27 |o \\.Uni|versit\'|
|00000410| 65 20 64 65 20 4e 69 63 | 65 7e 7e 2d 7e 7e 53 6f |e de Nic|e~~-~~So|
|00000420| 70 68 69 61 2d 41 6e 74 | 69 70 6f 6c 69 73 20 5c |phia-Ant|ipolis \|
|00000430| 5c 0a 4c 61 62 6f 72 61 | 74 6f 69 72 65 20 49 33 |\.Labora|toire I3|
|00000440| 53 20 2d 20 43 4e 52 53 | 20 55 52 41 20 31 33 37 |S - CNRS| URA 137|
|00000450| 36 20 2d 20 45 53 53 49 | 2e 20 5c 5c 0a 52 6f 75 |6 - ESSI|. \\.Rou|
|00000460| 74 65 20 64 65 73 20 43 | 6f 6c 6c 65 73 5c 5c 0a |te des C|olles\\.|
|00000470| 42 2e 50 2e 20 31 34 35 | 5c 5c 0a 30 36 39 30 33 |B.P. 145|\\.06903|
|00000480| 20 53 6f 70 68 69 61 2d | 41 6e 74 69 70 6f 6c 69 | Sophia-|Antipoli|
|00000490| 73 20 43 65 64 65 78 20 | 2d 20 46 52 41 4e 43 45 |s Cedex |- FRANCE|
|000004a0| 5c 5c 5b 33 6d 6d 5d 0a | 65 6d 61 69 6c 3a 20 65 |\\[3mm].|email: e|
|000004b0| 67 40 75 6e 69 63 65 2e | 66 72 7d 0a 5c 64 61 74 |g@unice.|fr}.\dat|
|000004c0| 65 7b 4a 75 6c 79 20 31 | 39 39 35 7d 0a 5c 6d 61 |e{July 1|995}.\ma|
|000004d0| 6b 65 74 69 74 6c 65 0a | 0a 5c 62 65 67 69 6e 7b |ketitle.|.\begin{|
|000004e0| 61 62 73 74 72 61 63 74 | 7d 0a 54 68 69 73 20 64 |abstract|}.This d|
|000004f0| 6f 63 75 6d 65 6e 74 20 | 64 65 73 63 72 69 62 65 |ocument |describe|
|00000500| 73 20 68 6f 77 20 74 6f | 20 65 78 74 65 6e 64 20 |s how to| extend |
|00000510| 74 68 65 20 7b 5c 73 74 | 6b 7d 20 69 6e 74 65 72 |the {\st|k} inter|
|00000520| 70 72 65 74 65 72 20 77 | 69 74 68 20 6e 65 77 0a |preter w|ith new.|
|00000530| 70 72 69 6d 69 74 69 76 | 65 73 20 70 72 6f 63 65 |primitiv|es proce|
|00000540| 64 75 72 65 73 20 61 6e | 64 2f 6f 72 20 6e 65 77 |dures an|d/or new|
|00000550| 20 74 79 70 65 73 2e 20 | 45 78 74 65 6e 64 69 6e | types. |Extendin|
|00000560| 67 20 74 68 65 20 69 6e | 74 65 72 70 72 65 74 65 |g the in|terprete|
|00000570| 72 20 63 61 6e 20 62 65 | 20 64 6f 6e 65 0a 62 79 |r can be| done.by|
|00000580| 20 77 72 69 74 69 6e 67 | 20 6e 65 77 20 7b 5c 65 | writing| new {\e|
|00000590| 6d 20 6d 6f 64 75 6c 65 | 73 7d 20 69 6e 20 43 2e |m module|s} in C.|
|000005a0| 20 4e 65 77 20 43 20 63 | 6f 64 65 20 63 61 6e 20 | New C c|ode can |
|000005b0| 62 65 20 73 74 61 74 69 | 63 61 6c 6c 79 20 6c 69 |be stati|cally li|
|000005c0| 6e 6b 65 64 20 74 6f 20 | 74 68 65 0a 63 6f 72 65 |nked to |the.core|
|000005d0| 20 69 6e 74 65 72 70 72 | 65 74 65 72 20 6f 72 20 | interpr|eter or |
|000005e0| 64 79 6e 61 6d 69 63 61 | 6c 6c 79 20 6c 6f 61 64 |dynamica|lly load|
|000005f0| 65 64 20 6f 6e 20 6f 70 | 65 72 61 74 69 6e 67 20 |ed on op|erating |
|00000600| 73 79 73 74 65 6d 73 20 | 77 68 69 63 68 20 73 75 |systems |which su|
|00000610| 70 70 6f 72 74 0a 73 68 | 61 72 65 64 20 6c 69 62 |pport.sh|ared lib|
|00000620| 72 61 72 69 65 73 2e 20 | 54 68 69 73 20 64 6f 63 |raries. |This doc|
|00000630| 75 6d 65 6e 74 20 61 6c | 73 6f 20 70 72 65 73 65 |ument al|so prese|
|00000640| 6e 74 73 20 68 6f 77 20 | 74 6f 20 69 6e 74 65 67 |nts how |to integ|
|00000650| 72 61 74 65 20 6e 65 77 | 0a 54 6b 20 77 69 64 67 |rate new|.Tk widg|
|00000660| 65 74 73 20 77 72 69 74 | 74 65 6e 20 66 6f 72 20 |ets writ|ten for |
|00000670| 74 68 65 20 54 63 6c 20 | 69 6e 74 65 72 70 72 65 |the Tcl |interpre|
|00000680| 74 65 72 20 69 6e 20 7b | 5c 73 74 6b 7d 2e 0a 5c |ter in {|\stk}..\|
|00000690| 65 6e 64 7b 61 62 73 74 | 72 61 63 74 7d 0a 0a 0a |end{abst|ract}...|
|000006a0| 5c 70 61 67 65 62 72 65 | 61 6b 0a 5c 74 61 62 6c |\pagebre|ak.\tabl|
|000006b0| 65 6f 66 63 6f 6e 74 65 | 6e 74 73 0a 5c 70 61 67 |eofconte|nts.\pag|
|000006c0| 65 62 72 65 61 6b 0a 5c | 73 65 63 74 69 6f 6e 7b |ebreak.\|section{|
|000006d0| 49 6e 74 72 6f 64 75 63 | 74 69 6f 6e 7d 0a 54 68 |Introduc|tion}.Th|
|000006e0| 69 73 20 64 6f 63 75 6d | 65 6e 74 20 64 65 73 63 |is docum|ent desc|
|000006f0| 72 69 62 65 73 20 68 6f | 77 20 74 6f 20 65 78 74 |ribes ho|w to ext|
|00000700| 65 6e 64 20 74 68 65 20 | 7b 5c 73 74 6b 7d 5c 63 |end the |{\stk}\c|
|00000710| 69 74 65 7b 47 61 6c 6c | 65 73 69 6f 39 33 2d 31 |ite{Gall|esio93-1|
|00000720| 7d 0a 69 6e 74 65 72 70 | 72 65 74 65 72 20 75 73 |}.interp|reter us|
|00000730| 69 6e 67 20 74 68 65 20 | 43 20 6c 61 6e 67 75 61 |ing the |C langua|
|00000740| 67 65 5c 63 69 74 65 7b | 4b 65 72 6e 69 67 68 61 |ge\cite{|Kernigha|
|00000750| 6e 3a 43 50 4c 38 38 7d | 2e 20 54 6f 20 62 65 67 |n:CPL88}|. To beg|
|00000760| 69 6e 2c 20 77 65 0a 77 | 69 6c 6c 20 73 74 61 72 |in, we.w|ill star|
|00000770| 74 20 77 69 74 68 20 61 | 20 73 69 6d 70 6c 65 20 |t with a| simple |
|00000780| 65 78 74 65 6e 73 69 6f | 6e 20 77 68 69 63 68 20 |extensio|n which |
|00000790| 77 69 6c 6c 20 6f 6e 6c | 79 20 63 6f 6e 73 69 73 |will onl|y consis|
|000007a0| 74 20 74 6f 20 61 64 64 | 20 73 6f 6d 65 0a 73 69 |t to add| some.si|
|000007b0| 6d 70 6c 65 20 6e 65 77 | 20 70 72 69 6d 69 74 69 |mple new| primiti|
|000007c0| 76 65 73 20 74 6f 20 74 | 68 65 20 69 6e 74 65 72 |ves to t|he inter|
|000007d0| 70 72 65 74 65 72 2e 20 | 53 65 63 6f 6e 64 20 73 |preter. |Second s|
|000007e0| 65 63 74 69 6f 6e 20 77 | 69 6c 6c 20 64 65 73 63 |ection w|ill desc|
|000007f0| 72 69 62 65 0a 68 6f 77 | 20 74 6f 20 61 64 64 20 |ribe.how| to add |
|00000800| 61 20 6e 65 77 20 74 79 | 70 65 20 28 61 6e 64 20 |a new ty|pe (and |
|00000810| 74 68 65 20 70 72 69 6d | 69 74 69 76 65 73 20 66 |the prim|itives f|
|00000820| 6f 72 20 6d 61 6e 69 70 | 75 6c 61 74 69 6e 67 20 |or manip|ulating |
|00000830| 74 68 69 73 20 6e 65 77 | 0a 74 79 70 65 29 2e 20 |this new|.type). |
|00000840| 41 6e 6f 74 68 65 72 20 | 69 6e 74 65 72 65 73 74 |Another |interest|
|00000850| 69 6e 67 20 65 78 74 65 | 6e 73 69 6f 6e 20 63 6f |ing exte|nsion co|
|00000860| 6e 73 69 73 74 73 20 74 | 6f 20 61 64 64 20 6e 65 |nsists t|o add ne|
|00000870| 77 20 6b 69 6e 64 20 6f | 66 0a 70 72 69 6d 69 74 |w kind o|f.primit|
|00000880| 69 76 65 73 20 28 69 2e | 65 2e 20 20 70 72 69 6d |ives (i.|e. prim|
|00000890| 69 74 69 76 65 73 20 77 | 68 69 63 68 20 65 76 61 |itives w|hich eva|
|000008a0| 6c 75 61 74 65 20 74 68 | 65 69 72 20 61 72 67 75 |luate th|eir argu|
|000008b0| 6d 65 6e 74 20 69 6e 0a | 70 61 72 74 69 63 75 6c |ment in.|particul|
|000008c0| 61 72 20 77 61 79 29 2e | 20 54 68 69 73 20 6b 69 |ar way).| This ki|
|000008d0| 6e 64 20 6f 66 20 65 78 | 74 65 6e 73 69 6f 6e 20 |nd of ex|tension |
|000008e0| 77 69 6c 6c 20 62 65 20 | 64 69 73 63 75 73 73 65 |will be |discusse|
|000008f0| 64 20 69 6e 20 74 68 65 | 20 74 68 69 72 64 0a 73 |d in the| third.s|
|00000900| 65 63 74 69 6f 6e 2e 20 | 20 46 6f 75 72 74 68 20 |ection. | Fourth |
|00000910| 73 65 63 74 69 6f 6e 20 | 64 69 73 63 75 73 73 65 |section |discusse|
|00000920| 73 20 68 6f 77 20 74 6f | 20 61 64 64 20 61 20 6e |s how to| add a n|
|00000930| 65 77 20 77 69 64 67 65 | 74 20 74 6f 20 74 68 65 |ew widge|t to the|
|00000940| 0a 69 6e 74 65 72 70 72 | 65 74 65 72 2e 20 43 61 |.interpr|eter. Ca|
|00000950| 6c 6c 69 6e 67 20 73 6f | 6d 65 20 53 63 68 65 6d |lling so|me Schem|
|00000960| 65 20 63 6f 64 65 20 66 | 72 6f 6d 20 61 20 43 20 |e code f|rom a C |
|00000970| 66 75 6e 63 74 69 6f 6e | 20 69 73 20 73 68 6f 77 |function| is show|
|00000980| 65 64 20 69 6e 0a 73 65 | 63 74 69 6f 6e 20 35 2e |ed in.se|ction 5.|
|00000990| 20 41 6e 64 20 6c 61 73 | 74 2c 20 77 65 20 77 69 | And las|t, we wi|
|000009a0| 6c 6c 20 73 68 6f 77 20 | 68 6f 77 20 74 6f 20 6c |ll show |how to l|
|000009b0| 6f 61 64 20 61 6e 20 65 | 78 74 65 6e 73 69 6f 6e |oad an e|xtension|
|000009c0| 20 61 74 20 6c 6f 61 64 | 0a 74 69 6d 65 2e 20 54 | at load|.time. T|
|000009d0| 68 69 73 20 66 61 63 69 | 6c 69 74 79 20 77 69 6c |his faci|lity wil|
|000009e0| 6c 20 70 65 72 6d 69 74 | 20 74 6f 20 65 78 74 65 |l permit| to exte|
|000009f0| 6e 64 20 74 68 65 20 7b | 5c 73 74 6b 7d 20 69 6e |nd the {|\stk} in|
|00000a00| 74 65 72 70 72 65 74 65 | 72 0a 77 69 74 68 6f 75 |terprete|r.withou|
|00000a10| 74 20 68 61 76 69 6e 67 | 20 74 6f 20 72 65 63 6f |t having| to reco|
|00000a20| 6d 70 69 6c 65 20 69 74 | 2c 20 6f 6e 20 73 79 73 |mpile it|, on sys|
|00000a30| 74 65 6d 73 20 77 68 69 | 63 68 20 73 75 70 70 6f |tems whi|ch suppo|
|00000a40| 72 74 20 64 79 6e 61 6d | 69 63 0a 6c 6f 61 64 69 |rt dynam|ic.loadi|
|00000a50| 6e 67 2e 0a 0a 5c 73 65 | 63 74 69 6f 6e 7b 41 64 |ng...\se|ction{Ad|
|00000a60| 64 69 6e 67 20 6e 65 77 | 20 70 72 69 6d 69 74 69 |ding new| primiti|
|00000a70| 76 65 73 7d 0a 0a 5c 73 | 75 62 73 65 63 74 69 6f |ves}..\s|ubsectio|
|00000a80| 6e 7b 41 20 73 69 6d 70 | 6c 65 20 65 78 61 6d 70 |n{A simp|le examp|
|00000a90| 6c 65 7d 0a 0a 5c 6c 61 | 62 65 6c 7b 73 69 6d 70 |le}..\la|bel{simp|
|00000aa0| 6c 65 2d 65 78 61 6d 70 | 6c 65 7d 0a 4f 6e 65 20 |le-examp|le}.One |
|00000ab0| 6f 66 20 74 68 65 20 73 | 69 6d 70 6c 65 72 20 65 |of the s|impler e|
|00000ac0| 78 74 65 6e 73 69 6f 6e | 20 6f 6e 65 20 63 61 6e |xtension| one can|
|00000ad0| 20 77 69 73 68 20 74 6f | 20 64 6f 20 63 6f 6e 73 | wish to| do cons|
|00000ae0| 69 73 74 73 20 74 6f 20 | 61 64 64 20 6e 65 77 0a |ists to |add new.|
|00000af0| 70 72 69 6d 69 74 69 76 | 65 73 20 70 72 6f 63 65 |primitiv|es proce|
|00000b00| 64 75 72 65 73 20 74 6f | 20 74 68 65 20 69 6e 74 |dures to| the int|
|00000b10| 65 72 70 72 65 74 65 72 | 2e 20 54 6f 20 69 6c 6c |erpreter|. To ill|
|00000b20| 75 73 74 72 61 74 65 20 | 74 68 69 73 2c 20 73 75 |ustrate |this, su|
|00000b30| 70 70 6f 73 65 0a 77 65 | 20 77 61 6e 74 20 74 6f |ppose.we| want to|
|00000b40| 20 61 64 64 20 74 77 6f | 20 6e 65 77 20 70 72 69 | add two| new pri|
|00000b50| 6d 69 74 69 76 65 73 20 | 74 6f 20 74 68 65 20 69 |mitives |to the i|
|00000b60| 6e 74 65 72 70 72 65 74 | 65 72 3a 20 7b 5c 74 74 |nterpret|er: {\tt|
|00000b70| 20 70 6f 73 69 78 2d 74 | 69 6d 65 7d 0a 61 6e 64 | posix-t|ime}.and|
|00000b80| 20 7b 5c 74 74 20 70 6f | 73 69 78 2d 63 74 69 6d | {\tt po|six-ctim|
|00000b90| 65 7d 2e 20 20 54 68 65 | 20 66 6f 72 6d 65 72 20 |e}. The| former |
|00000ba0| 66 75 6e 63 74 69 6f 6e | 20 63 6f 72 72 65 73 70 |function| corresp|
|00000bb0| 6f 6e 64 20 74 6f 20 74 | 68 65 0a 50 4f 53 49 58 |ond to t|he.POSIX|
|00000bc0| 2e 31 5c 63 69 74 65 7b | 50 4f 53 49 58 2e 31 2d |.1\cite{|POSIX.1-|
|00000bd0| 39 30 7d 20 66 75 6e 63 | 74 69 6f 6e 20 7b 5c 74 |90} func|tion {\t|
|00000be0| 74 20 74 69 6d 65 7d 3a | 20 69 74 20 72 65 74 75 |t time}:| it retu|
|00000bf0| 72 6e 73 20 74 68 65 20 | 6e 75 6d 62 65 72 0a 6f |rns the |number.o|
|00000c00| 66 20 73 65 63 6f 6e 64 | 73 20 65 6c 61 70 73 65 |f second|s elapse|
|00000c10| 64 20 73 69 6e 63 65 20 | 30 30 3a 30 30 3a 30 30 |d since |00:00:00|
|00000c20| 20 6f 6e 20 4a 61 6e 75 | 61 72 79 20 31 2c 20 31 | on Janu|ary 1, 1|
|00000c30| 39 37 30 2c 20 43 6f 6f | 72 64 69 6e 61 74 65 64 |970, Coo|rdinated|
|00000c40| 0a 55 6e 69 76 65 72 73 | 61 6c 20 54 69 6d 65 20 |.Univers|al Time |
|00000c50| 28 55 54 43 29 2e 20 20 | 54 68 65 20 6c 61 74 74 |(UTC). |The latt|
|00000c60| 65 72 20 69 73 20 61 20 | 77 72 61 70 70 65 72 20 |er is a |wrapper |
|00000c70| 61 72 6f 75 6e 64 20 74 | 68 65 20 50 4f 53 49 58 |around t|he POSIX|
|00000c80| 2e 31 0a 66 75 6e 63 74 | 69 6f 6e 20 7b 5c 74 74 |.1.funct|ion {\tt|
|00000c90| 20 63 74 69 6d 65 7d 20 | 77 68 69 63 68 20 72 65 | ctime} |which re|
|00000ca0| 74 75 72 6e 73 20 61 20 | 73 74 72 69 6e 67 20 63 |turns a |string c|
|00000cb0| 6f 6e 74 61 69 6e 69 6e | 67 20 74 68 65 20 63 75 |ontainin|g the cu|
|00000cc0| 72 72 65 6e 74 0a 74 69 | 6d 65 20 69 6e 20 61 6e |rrent.ti|me in an|
|00000cd0| 20 68 75 6d 61 6e 20 72 | 65 61 64 61 62 6c 65 20 | human r|eadable |
|00000ce0| 66 6f 72 6d 61 74 2e 0a | 0a 46 69 72 73 74 2c 20 |format..|.First, |
|00000cf0| 77 65 20 77 69 6c 6c 20 | 73 65 65 20 68 6f 77 20 |we will |see how |
|00000d00| 74 6f 20 77 72 69 74 65 | 20 74 68 65 20 6e 65 77 |to write| the new|
|00000d10| 20 53 63 68 65 6d 65 20 | 70 72 69 6d 69 74 69 76 | Scheme |primitiv|
|00000d20| 65 20 7b 5c 74 74 20 70 | 6f 73 69 78 2d 74 69 6d |e {\tt p|osix-tim|
|00000d30| 65 7d 2e 0a 49 6d 70 6c | 65 6d 65 6e 74 69 6e 67 |e}..Impl|ementing|
|00000d40| 20 61 20 6e 65 77 20 70 | 72 69 6d 69 74 69 76 65 | a new p|rimitive|
|00000d50| 20 72 65 71 75 69 72 65 | 73 20 74 6f 20 77 72 69 | require|s to wri|
|00000d60| 74 65 20 61 20 6e 65 77 | 20 43 20 66 75 6e 63 74 |te a new| C funct|
|00000d70| 69 6f 6e 20 77 68 69 63 | 68 20 77 69 6c 6c 20 64 |ion whic|h will d|
|00000d80| 6f 0a 74 68 65 20 77 6f | 72 6b 2e 20 48 65 72 65 |o.the wo|rk. Here|
|00000d90| 2c 20 77 65 20 77 72 69 | 74 65 20 74 68 65 20 43 |, we wri|te the C|
|00000da0| 20 66 75 6e 63 74 69 6f | 6e 20 7b 5c 74 74 20 70 | functio|n {\tt p|
|00000db0| 6f 73 69 78 5c 5f 74 69 | 6d 65 7d 20 74 6f 20 69 |osix\_ti|me} to i|
|00000dc0| 6d 70 6c 65 6d 65 6e 74 | 20 74 68 65 0a 53 63 68 |mplement| the.Sch|
|00000dd0| 65 6d 65 20 70 72 69 6d | 69 74 69 76 65 20 7b 5c |eme prim|itive {\|
|00000de0| 74 74 20 70 6f 73 69 78 | 2d 74 69 6d 65 7d 2e 20 |tt posix|-time}. |
|00000df0| 54 68 65 20 63 6f 64 65 | 20 6f 66 20 74 68 69 73 |The code| of this|
|00000e00| 20 66 75 6e 63 74 69 6f | 6e 20 69 73 20 67 69 76 | functio|n is giv|
|00000e10| 65 6e 20 62 65 6c 6f 77 | 2e 0a 5c 62 65 67 69 6e |en below|..\begin|
|00000e20| 7b 43 6f 64 65 7d 0a 5c | 62 65 67 69 6e 7b 6c 69 |{Code}.\|begin{li|
|00000e30| 73 74 69 6e 67 7d 5b 32 | 30 30 5d 7b 32 7d 0a 73 |sting}[2|00]{2}.s|
|00000e40| 74 61 74 69 63 20 50 52 | 49 4d 49 54 49 56 45 20 |tatic PR|IMITIVE |
|00000e50| 70 6f 73 69 78 5f 74 69 | 6d 65 28 76 6f 69 64 29 |posix_ti|me(void)|
|00000e60| 0a 7b 0a 20 20 72 65 74 | 75 72 6e 20 53 54 6b 5f |.{. ret|urn STk_|
|00000e70| 6d 61 6b 65 69 6e 74 65 | 67 65 72 28 28 6c 6f 6e |makeinte|ger((lon|
|00000e80| 67 29 20 74 69 6d 65 28 | 4e 55 4c 4c 29 29 3b 0a |g) time(|NULL));.|
|00000e90| 7d 0a 5c 65 6e 64 7b 6c | 69 73 74 69 6e 67 7d 0a |}.\end{l|isting}.|
|00000ea0| 5c 65 6e 64 7b 43 6f 64 | 65 7d 0a 54 68 69 73 20 |\end{Cod|e}.This |
|00000eb0| 66 75 6e 63 74 69 6f 6e | 20 75 73 65 73 20 74 68 |function| uses th|
|00000ec0| 65 20 69 6e 74 65 72 70 | 72 65 74 65 72 20 5c 49 |e interp|reter \I|
|00000ed0| 6e 64 65 78 74 74 7b 53 | 54 6b 5c 5f 6d 61 6b 65 |ndextt{S|Tk\_make|
|00000ee0| 69 6e 74 65 67 65 72 7d | 20 66 75 6e 63 74 69 6f |integer}| functio|
|00000ef0| 6e 0a 77 68 69 63 68 20 | 63 6f 6e 76 65 72 74 73 |n.which |converts|
|00000f00| 20 61 20 43 20 6c 6f 6e | 67 20 69 6e 74 65 67 65 | a C lon|g intege|
|00000f10| 72 20 74 6f 20 61 20 7b | 5c 73 74 6b 7d 20 69 6e |r to a {|\stk} in|
|00000f20| 74 65 67 65 72 2e 20 4f | 6e 63 65 20 74 68 65 20 |teger. O|nce the |
|00000f30| 7b 5c 74 74 0a 70 6f 73 | 69 78 5c 5f 74 69 6d 65 |{\tt.pos|ix\_time|
|00000f40| 7d 20 43 20 66 75 6e 63 | 74 69 6f 6e 20 69 73 20 |} C func|tion is |
|00000f50| 77 72 69 74 74 65 6e 2c | 20 77 65 20 68 61 76 65 |written,| we have|
|00000f60| 20 74 6f 20 62 69 6e 64 | 20 74 68 69 73 20 6e 65 | to bind| this ne|
|00000f70| 77 20 70 72 69 6d 69 74 | 69 76 65 20 74 6f 0a 74 |w primit|ive to.t|
|00000f80| 68 65 20 53 63 68 65 6d | 65 20 73 79 6d 62 6f 6c |he Schem|e symbol|
|00000f90| 20 7b 5c 74 74 20 70 6f | 73 69 78 2d 74 69 6d 65 | {\tt po|six-time|
|00000fa0| 7d 2e 20 54 68 69 73 20 | 69 73 20 61 63 68 69 65 |}. This |is achie|
|00000fb0| 76 65 64 20 62 79 20 74 | 68 65 20 66 6f 6c 6c 6f |ved by t|he follo|
|00000fc0| 77 69 6e 67 20 43 0a 66 | 75 6e 63 74 69 6f 6e 20 |wing C.f|unction |
|00000fd0| 63 61 6c 6c 2e 0a 5c 62 | 65 67 69 6e 7b 43 6f 64 |call..\b|egin{Cod|
|00000fe0| 65 7d 0a 5c 62 65 67 69 | 6e 7b 6c 69 73 74 69 6e |e}.\begi|n{listin|
|00000ff0| 67 7d 5b 32 30 30 5d 7b | 32 7d 0a 53 54 6b 5f 61 |g}[200]{|2}.STk_a|
|00001000| 64 64 5f 6e 65 77 5f 70 | 72 69 6d 69 74 69 76 65 |dd_new_p|rimitive|
|00001010| 28 22 70 6f 73 69 78 2d | 74 69 6d 65 22 2c 20 74 |("posix-|time", t|
|00001020| 63 5f 73 75 62 72 5f 30 | 2c 20 70 6f 73 69 78 5f |c_subr_0|, posix_|
|00001030| 74 69 6d 65 29 3b 0a 5c | 65 6e 64 7b 6c 69 73 74 |time);.\|end{list|
|00001040| 69 6e 67 7d 0a 5c 65 6e | 64 7b 43 6f 64 65 7d 0a |ing}.\en|d{Code}.|
|00001050| 0a 5c 70 61 72 61 67 72 | 61 70 68 2a 7b 4e 6f 74 |.\paragr|aph*{Not|
|00001060| 65 3a 7d 20 54 68 65 20 | 43 20 74 79 70 65 20 5c |e:} The |C type \|
|00001070| 49 6e 64 65 78 74 74 7b | 53 43 4d 7d 20 69 73 20 |Indextt{|SCM} is |
|00001080| 75 73 65 64 20 74 6f 20 | 64 65 73 63 72 69 62 65 |used to |describe|
|00001090| 20 74 68 65 20 6f 62 6a | 65 63 74 73 0a 6d 61 6e | the obj|ects.man|
|000010a0| 69 70 75 6c 61 74 65 64 | 20 69 6e 20 53 63 68 65 |ipulated| in Sche|
|000010b0| 6d 65 2e 20 5c 49 6e 64 | 65 78 74 74 7b 50 52 49 |me. \Ind|extt{PRI|
|000010c0| 4d 49 54 49 56 45 7d 20 | 69 73 20 61 6e 20 61 6c |MITIVE} |is an al|
|000010d0| 69 61 73 20 66 6f 72 20 | 74 68 69 73 20 74 79 70 |ias for |this typ|
|000010e0| 65 3b 20 69 74 0a 69 73 | 20 70 72 65 66 65 72 61 |e; it.is| prefera|
|000010f0| 62 6c 79 20 75 73 65 64 | 20 77 68 65 6e 20 64 65 |bly used| when de|
|00001100| 66 69 6e 69 6e 67 20 61 | 20 6e 65 77 20 70 72 69 |fining a| new pri|
|00001110| 6d 69 74 69 76 65 2e 0a | 0a 5c 49 6e 64 65 78 74 |mitive..|.\Indext|
|00001120| 74 7b 53 54 6b 5c 5f 61 | 64 64 5c 5f 6e 65 77 5c |t{STk\_a|dd\_new\|
|00001130| 5f 70 72 69 6d 69 74 69 | 76 65 7d 20 74 65 6c 6c |_primiti|ve} tell|
|00001140| 73 20 74 68 65 20 69 6e | 74 65 72 70 72 65 74 65 |s the in|terprete|
|00001150| 72 20 74 68 61 74 20 74 | 68 65 20 53 63 68 65 6d |r that t|he Schem|
|00001160| 65 20 0a 73 79 6d 62 6f | 6c 20 7b 5c 74 74 20 70 |e .symbo|l {\tt p|
|00001170| 6f 73 69 78 2d 74 69 6d | 65 7d 20 6d 75 73 74 20 |osix-tim|e} must |
|00001180| 62 65 20 62 6f 75 6e 64 | 20 74 6f 20 74 68 65 20 |be bound| to the |
|00001190| 28 43 20 77 72 69 74 74 | 65 6e 29 20 70 72 69 6d |(C writt|en) prim|
|000011a0| 69 74 69 76 65 0a 7b 5c | 74 74 20 70 6f 73 69 78 |itive.{\|tt posix|
|000011b0| 5c 5f 74 69 6d 65 7d 2e | 20 20 54 68 65 20 63 6f |\_time}.| The co|
|000011c0| 6e 73 74 61 6e 74 20 5c | 49 6e 64 65 78 74 74 7b |nstant \|Indextt{|
|000011d0| 74 63 5c 5f 73 75 62 72 | 5c 5f 30 7d 20 75 73 65 |tc\_subr|\_0} use|
|000011e0| 64 20 61 73 20 74 68 65 | 20 73 65 63 6f 6e 64 0a |d as the| second.|
|000011f0| 61 72 67 75 6d 65 6e 74 | 20 69 6e 64 69 63 61 74 |argument| indicat|
|00001200| 65 73 20 74 68 65 20 61 | 72 69 74 79 20 6f 66 20 |es the a|rity of |
|00001210| 74 68 69 73 20 70 72 69 | 6d 69 74 69 76 65 2e 20 |this pri|mitive. |
|00001220| 49 6e 20 74 68 69 73 20 | 63 61 73 65 2c 20 74 68 |In this |case, th|
|00001230| 65 0a 61 72 69 74 79 20 | 6f 66 20 74 68 65 20 70 |e.arity |of the p|
|00001240| 72 69 6d 69 74 69 76 65 | 20 69 73 20 30 2e 0a 0a |rimitive| is 0...|
|00001250| 4c 65 74 27 73 20 6e 6f | 77 20 68 61 76 65 20 61 |Let's no|w have a|
|00001260| 20 6c 6f 6f 6b 20 61 74 | 20 74 68 65 20 70 72 69 | look at| the pri|
|00001270| 6d 69 74 69 76 65 20 7b | 5c 74 74 20 70 6f 73 69 |mitive {|\tt posi|
|00001280| 78 2d 63 74 69 6d 65 7d | 2e 20 41 20 66 69 72 73 |x-ctime}|. A firs|
|00001290| 74 0a 77 72 69 74 69 6e | 67 20 6f 66 20 74 68 69 |t.writin|g of thi|
|000012a0| 73 20 70 72 69 6d 69 74 | 69 76 65 20 63 6f 75 6c |s primit|ive coul|
|000012b0| 64 20 62 65 0a 5c 62 65 | 67 69 6e 7b 43 6f 64 65 |d be.\be|gin{Code|
|000012c0| 7d 0a 5c 62 65 67 69 6e | 7b 6c 69 73 74 69 6e 67 |}.\begin|{listing|
|000012d0| 7d 5b 32 30 30 5d 7b 32 | 7d 0a 73 74 61 74 69 63 |}[200]{2|}.static|
|000012e0| 20 50 52 49 4d 49 54 49 | 56 45 20 70 6f 73 69 78 | PRIMITI|VE posix|
|000012f0| 5f 63 74 69 6d 65 28 76 | 6f 69 64 29 0a 7b 0a 20 |_ctime(v|oid).{. |
|00001300| 20 63 68 61 72 20 2a 73 | 3b 0a 20 20 74 69 6d 65 | char *s|;. time|
|00001310| 5f 74 20 74 20 3d 20 74 | 69 6d 65 28 4e 55 4c 4c |_t t = t|ime(NULL|
|00001320| 29 3b 0a 0a 20 20 73 20 | 3d 20 63 74 69 6d 65 28 |);.. s |= ctime(|
|00001330| 26 74 29 3b 0a 20 20 72 | 65 74 75 72 6e 20 53 54 |&t);. r|eturn ST|
|00001340| 6b 5f 6d 61 6b 65 73 74 | 72 69 6e 67 28 73 29 3b |k_makest|ring(s);|
|00001350| 0a 7d 0a 5c 65 6e 64 7b | 6c 69 73 74 69 6e 67 7d |.}.\end{|listing}|
|00001360| 0a 5c 65 6e 64 7b 43 6f | 64 65 7d 0a 0a 54 68 69 |.\end{Co|de}..Thi|
|00001370| 73 20 66 75 6e 63 74 69 | 6f 6e 73 20 75 73 65 73 |s functi|ons uses|
|00001380| 20 61 6e 6f 74 68 65 72 | 20 69 6e 74 65 72 70 72 | another| interpr|
|00001390| 65 74 65 72 20 72 6f 75 | 74 69 6e 65 20 28 5c 49 |eter rou|tine (\I|
|000013a0| 6e 64 65 78 74 74 7b 53 | 54 6b 5c 5f 6d 61 6b 65 |ndextt{S|Tk\_make|
|000013b0| 73 74 72 69 6e 67 7d 29 | 0a 77 68 69 63 68 20 74 |string})|.which t|
|000013c0| 61 6b 65 73 20 61 73 20 | 70 61 72 61 6d 65 74 65 |akes as |paramete|
|000013d0| 72 20 61 20 6e 75 6c 6c | 20 74 65 72 6d 69 6e 61 |r a null| termina|
|000013e0| 74 65 64 20 73 74 72 69 | 6e 67 20 61 6e 64 20 72 |ted stri|ng and r|
|000013f0| 65 74 75 72 6e 73 20 61 | 0a 53 63 68 65 6d 65 20 |eturns a|.Scheme |
|00001400| 73 74 72 69 6e 67 2e 20 | 0a 0a 42 69 6e 64 69 6e |string. |..Bindin|
|00001410| 67 20 6f 66 20 74 68 65 | 20 73 63 68 65 6d 65 20 |g of the| scheme |
|00001420| 73 79 6d 62 6f 6c 20 7b | 5c 74 74 20 74 69 6d 65 |symbol {|\tt time|
|00001430| 2d 73 74 72 69 6e 67 7d | 20 74 6f 20 74 68 65 20 |-string}| to the |
|00001440| 43 20 66 75 6e 63 74 69 | 6f 6e 20 0a 7b 5c 74 74 |C functi|on .{\tt|
|00001450| 20 67 65 74 5c 5f 74 69 | 6d 65 7d 20 69 73 20 64 | get\_ti|me} is d|
|00001460| 6f 6e 65 20 62 79 20 74 | 68 65 20 63 61 6c 6c 20 |one by t|he call |
|00001470| 0a 5c 62 65 67 69 6e 7b | 43 6f 64 65 7d 0a 5c 62 |.\begin{|Code}.\b|
|00001480| 65 67 69 6e 7b 6c 69 73 | 74 69 6e 67 7d 5b 32 30 |egin{lis|ting}[20|
|00001490| 30 5d 7b 32 7d 0a 53 54 | 6b 5f 61 64 64 5f 6e 65 |0]{2}.ST|k_add_ne|
|000014a0| 77 5f 70 72 69 6d 69 74 | 69 76 65 28 22 70 6f 73 |w_primit|ive("pos|
|000014b0| 69 78 2d 63 74 69 6d 65 | 22 2c 20 74 63 5f 73 75 |ix-ctime|", tc_su|
|000014c0| 62 72 5f 30 2c 20 70 6f | 73 69 78 5f 63 74 69 6d |br_0, po|six_ctim|
|000014d0| 65 29 3b 0a 5c 65 6e 64 | 7b 6c 69 73 74 69 6e 67 |e);.\end|{listing|
|000014e0| 7d 0a 5c 65 6e 64 7b 43 | 6f 64 65 7d 0a 0a 41 20 |}.\end{C|ode}..A |
|000014f0| 63 6f 6d 70 6c 65 74 65 | 20 6c 69 73 74 69 6e 67 |complete| listing|
|00001500| 20 6f 66 20 74 68 69 73 | 20 63 6f 64 65 20 69 73 | of this| code is|
|00001510| 20 67 69 76 65 6e 20 69 | 6e 20 46 69 67 75 72 65 | given i|n Figure|
|00001520| 7e 5c 72 65 66 7b 70 6f | 73 69 78 2d 31 7d 2e 0a |~\ref{po|six-1}..|
|00001530| 50 72 6f 76 69 64 65 64 | 20 74 68 61 74 20 77 65 |Provided| that we|
|00001540| 20 68 61 76 65 20 64 6f | 6e 65 20 61 20 73 68 61 | have do|ne a sha|
|00001550| 72 65 64 20 6f 62 6a 65 | 63 74 20 6f 66 20 74 68 |red obje|ct of th|
|00001560| 69 73 20 66 69 6c 65 2c | 20 61 6e 64 20 74 68 61 |is file,| and tha|
|00001570| 74 20 69 74 73 0a 6e 61 | 6d 65 20 69 73 20 7b 5c |t its.na|me is {\|
|00001580| 74 74 20 70 6f 73 69 78 | 2e 73 6f 7d 2c 20 6f 75 |tt posix|.so}, ou|
|00001590| 72 20 74 77 6f 20 6e 65 | 77 20 70 72 69 6d 69 74 |r two ne|w primit|
|000015a0| 69 76 65 73 20 63 61 6e | 20 62 65 20 6c 6f 61 64 |ives can| be load|
|000015b0| 65 64 0a 64 79 6e 61 6d | 69 63 61 6c 6c 79 20 62 |ed.dynam|ically b|
|000015c0| 79 3a 0a 5c 62 65 67 69 | 6e 7b 43 6f 64 65 7d 0a |y:.\begi|n{Code}.|
|000015d0| 5c 62 65 67 69 6e 7b 6c | 69 73 74 69 6e 67 7d 5b |\begin{l|isting}[|
|000015e0| 32 30 30 5d 7b 32 7d 0a | 28 6c 6f 61 64 20 22 74 |200]{2}.|(load "t|
|000015f0| 69 6d 65 2e 73 6f 22 29 | 0a 5c 65 6e 64 7b 6c 69 |ime.so")|.\end{li|
|00001600| 73 74 69 6e 67 7d 0a 5c | 65 6e 64 7b 43 6f 64 65 |sting}.\|end{Code|
|00001610| 7d 0a 0a 5c 70 61 72 61 | 67 72 61 70 68 2a 7b 4e |}..\para|graph*{N|
|00001620| 6f 74 65 73 3a 7d 0a 5c | 62 65 67 69 6e 7b 69 74 |otes:}.\|begin{it|
|00001630| 65 6d 69 7a 65 7d 0a 5c | 69 74 65 6d 20 53 75 66 |emize}.\|item Suf|
|00001640| 66 69 78 20 63 61 6e 20 | 62 65 20 6f 6d 69 74 74 |fix can |be omitt|
|00001650| 65 64 2e 20 53 75 66 66 | 69 78 65 73 20 67 69 76 |ed. Suff|ixes giv|
|00001660| 65 6e 20 69 6e 20 74 68 | 65 20 53 63 68 65 6d 65 |en in th|e Scheme|
|00001670| 20 76 61 72 69 61 62 6c | 65 20 0a 5c 49 6e 64 65 | variabl|e .\Inde|
|00001680| 78 74 74 7b 2a 6c 6f 61 | 64 2d 73 75 66 66 69 78 |xtt{*loa|d-suffix|
|00001690| 65 73 2a 7d 20 67 69 76 | 65 73 20 74 68 65 20 6f |es*} giv|es the o|
|000016a0| 72 64 65 72 20 69 6e 20 | 77 68 69 63 68 20 73 75 |rder in |which su|
|000016b0| 66 66 69 78 65 73 20 6d | 75 73 74 20 62 65 0a 74 |ffixes m|ust be.t|
|000016c0| 72 69 65 64 20 66 6f 72 | 20 6c 6f 61 64 69 6e 67 |ried for| loading|
|000016d0| 20 61 20 66 69 6c 65 2e | 20 20 44 65 66 61 75 6c | a file.| Defaul|
|000016e0| 74 20 76 61 6c 75 65 20 | 66 6f 72 20 74 68 69 73 |t value |for this|
|000016f0| 20 76 61 72 69 61 62 6c | 65 20 69 73 0a 7b 5c 74 | variabl|e is.{\t|
|00001700| 74 20 28 22 73 74 6b 22 | 20 22 73 74 6b 6c 6f 73 |t ("stk"| "stklos|
|00001710| 22 20 22 73 63 6d 22 20 | 22 73 6f 22 29 7d 2e 0a |" "scm" |"so")}..|
|00001720| 0a 5c 69 74 65 6d 20 57 | 68 65 6e 20 64 79 6e 61 |.\item W|hen dyna|
|00001730| 6d 69 63 20 6c 6f 61 64 | 69 6e 67 20 69 73 20 75 |mic load|ing is u|
|00001740| 73 65 64 2c 20 74 68 65 | 20 69 6e 74 65 72 70 72 |sed, the| interpr|
|00001750| 65 74 65 72 20 74 72 79 | 20 74 6f 20 63 61 6c 6c |eter try| to call|
|00001760| 20 61 20 0a 66 75 6e 63 | 74 69 6f 6e 20 77 68 6f | a .func|tion who|
|00001770| 73 65 20 6e 61 6d 65 20 | 69 73 20 65 71 75 61 6c |se name |is equal|
|00001780| 20 74 6f 20 74 68 65 20 | 73 74 72 69 6e 67 20 7b | to the |string {|
|00001790| 5c 74 74 20 22 53 54 6b | 5c 5f 69 6e 69 74 5c 5f |\tt "STk|\_init\_|
|000017a0| 22 7d 20 66 6f 6c 6c 6f | 77 65 64 20 62 79 20 74 |"} follo|wed by t|
|000017b0| 68 65 0a 6e 61 6d 65 20 | 6f 66 20 74 68 65 20 66 |he.name |of the f|
|000017c0| 69 6c 65 2c 20 77 69 74 | 68 6f 75 74 20 73 75 66 |ile, wit|hout suf|
|000017d0| 66 69 78 2e 20 44 65 66 | 69 6e 69 74 69 6f 6e 73 |fix. Def|initions|
|000017e0| 20 6f 66 20 6e 65 77 20 | 70 72 69 6d 69 74 69 76 | of new |primitiv|
|000017f0| 65 73 20 61 72 65 20 67 | 65 6e 65 72 61 6c 6c 79 |es are g|enerally|
|00001800| 20 64 6f 6e 65 0a 69 6e | 20 74 68 69 73 20 66 75 | done.in| this fu|
|00001810| 6e 63 74 69 6f 6e 2e 20 | 48 65 72 65 2c 20 74 68 |nction. |Here, th|
|00001820| 65 20 43 20 66 75 6e 63 | 74 69 6f 6e 20 69 6e 20 |e C func|tion in |
|00001830| 63 68 61 72 67 65 20 6f | 66 20 6d 6f 64 75 6c 65 |charge o|f module|
|00001840| 20 69 6e 69 74 69 61 6c | 69 7a 61 74 69 6f 6e 20 | initial|ization |
|00001850| 6d 75 73 74 0a 62 65 20 | 63 61 6c 6c 65 64 20 7b |must.be |called {|
|00001860| 5c 74 74 20 53 54 6b 5c | 5f 69 6e 69 74 5c 5f 70 |\tt STk\|_init\_p|
|00001870| 6f 73 69 78 7d 2e 0a 5c | 65 6e 64 7b 69 74 65 6d |osix}..\|end{item|
|00001880| 69 7a 65 7d 0a 0a 25 25 | 25 25 25 25 25 25 25 25 |ize}..%%|%%%%%%%%|
|00001890| 25 25 25 25 25 25 25 25 | 25 25 25 25 25 25 25 25 |%%%%%%%%|%%%%%%%%|
|000018a0| 25 25 25 25 25 25 25 25 | 25 25 25 25 25 25 25 25 |%%%%%%%%|%%%%%%%%|
|000018b0| 25 25 25 25 25 25 25 25 | 25 25 25 25 25 25 25 25 |%%%%%%%%|%%%%%%%%|
|000018c0| 25 25 25 25 25 25 25 25 | 25 25 25 25 25 25 25 25 |%%%%%%%%|%%%%%%%%|
|000018d0| 25 25 25 25 0a 5c 62 65 | 67 69 6e 7b 66 69 67 75 |%%%%.\be|gin{figu|
|000018e0| 72 65 7d 0a 5c 62 65 67 | 69 6e 7b 71 75 6f 74 65 |re}.\beg|in{quote|
|000018f0| 7d 20 5c 66 6f 6f 74 6e | 6f 74 65 73 69 7a 65 0a |} \footn|otesize.|
|00001900| 5c 62 65 67 69 6e 7b 61 | 6c 6c 74 74 7d 0a 23 69 |\begin{a|lltt}.#i|
|00001910| 6e 63 6c 75 64 65 20 3c | 73 79 73 2f 74 79 70 65 |nclude <|sys/type|
|00001920| 73 2e 68 3e 0a 23 69 6e | 63 6c 75 64 65 20 3c 73 |s.h>.#in|clude <s|
|00001930| 79 73 2f 74 69 6d 65 2e | 68 3e 0a 23 69 6e 63 6c |ys/time.|h>.#incl|
|00001940| 75 64 65 20 3c 74 69 6d | 65 2e 68 3e 0a 23 69 6e |ude <tim|e.h>.#in|
|00001950| 63 6c 75 64 65 20 3c 73 | 74 6b 2e 68 3e 20 20 20 |clude <s|tk.h> |
|00001960| 20 20 20 20 20 7b 5c 65 | 6d 20 2f 2a 20 44 65 63 | {\e|m /* Dec|
|00001970| 6c 61 72 61 74 69 6f 6e | 20 6f 66 20 53 54 6b 20 |laration| of STk |
|00001980| 6f 62 6a 65 63 74 73 2f | 70 72 69 6d 69 74 69 76 |objects/|primitiv|
|00001990| 65 73 20 2a 2f 7d 0a 0a | 73 74 61 74 69 63 20 50 |es */}..|static P|
|000019a0| 52 49 4d 49 54 49 56 45 | 20 70 6f 73 69 78 5f 74 |RIMITIVE| posix_t|
|000019b0| 69 6d 65 28 76 6f 69 64 | 29 0a 5c 7b 0a 20 20 72 |ime(void|).\{. r|
|000019c0| 65 74 75 72 6e 20 53 54 | 6b 5f 6d 61 6b 65 69 6e |eturn ST|k_makein|
|000019d0| 74 65 67 65 72 28 28 6c | 6f 6e 67 29 20 74 69 6d |teger((l|ong) tim|
|000019e0| 65 28 4e 55 4c 4c 29 29 | 3b 0a 5c 7d 0a 0a 73 74 |e(NULL))|;.\}..st|
|000019f0| 61 74 69 63 20 50 52 49 | 4d 49 54 49 56 45 20 70 |atic PRI|MITIVE p|
|00001a00| 6f 73 69 78 5f 63 74 69 | 6d 65 28 76 6f 69 64 29 |osix_cti|me(void)|
|00001a10| 0a 5c 7b 0a 20 20 63 68 | 61 72 20 2a 73 3b 0a 20 |.\{. ch|ar *s;. |
|00001a20| 20 74 69 6d 65 5f 74 20 | 74 20 3d 20 74 69 6d 65 | time_t |t = time|
|00001a30| 28 4e 55 4c 4c 29 3b 0a | 0a 20 20 73 20 3d 20 63 |(NULL);.|. s = c|
|00001a40| 74 69 6d 65 28 26 74 29 | 3b 0a 20 20 72 65 74 75 |time(&t)|;. retu|
|00001a50| 72 6e 20 53 54 6b 5f 6d | 61 6b 65 73 74 72 69 6e |rn STk_m|akestrin|
|00001a60| 67 28 73 29 3b 0a 5c 7d | 0a 0a 50 52 49 4d 49 54 |g(s);.\}|..PRIMIT|
|00001a70| 49 56 45 20 53 54 6b 5f | 69 6e 69 74 5f 70 6f 73 |IVE STk_|init_pos|
|00001a80| 69 78 28 76 6f 69 64 29 | 0a 5c 7b 0a 20 20 53 54 |ix(void)|.\{. ST|
|00001a90| 6b 5f 61 64 64 5f 6e 65 | 77 5f 70 72 69 6d 69 74 |k_add_ne|w_primit|
|00001aa0| 69 76 65 28 22 70 6f 73 | 69 78 2d 74 69 6d 65 22 |ive("pos|ix-time"|
|00001ab0| 2c 20 20 74 63 5f 73 75 | 62 72 5f 30 2c 20 70 6f |, tc_su|br_0, po|
|00001ac0| 73 69 78 5f 74 69 6d 65 | 29 3b 0a 20 20 53 54 6b |six_time|);. STk|
|00001ad0| 5f 61 64 64 5f 6e 65 77 | 5f 70 72 69 6d 69 74 69 |_add_new|_primiti|
|00001ae0| 76 65 28 22 70 6f 73 69 | 78 2d 63 74 69 6d 65 22 |ve("posi|x-ctime"|
|00001af0| 2c 20 74 63 5f 73 75 62 | 72 5f 30 2c 20 70 6f 73 |, tc_sub|r_0, pos|
|00001b00| 69 78 5f 63 74 69 6d 65 | 29 3b 0a 20 20 72 65 74 |ix_ctime|);. ret|
|00001b10| 75 72 6e 20 55 4e 44 45 | 46 49 4e 45 44 3b 0a 5c |urn UNDE|FINED;.\|
|00001b20| 7d 0a 5c 65 6e 64 7b 61 | 6c 6c 74 74 7d 0a 7b 5c |}.\end{a|lltt}.{\|
|00001b30| 63 61 70 74 69 6f 6e 7b | 41 20 66 69 72 73 74 20 |caption{|A first |
|00001b40| 76 65 72 73 69 6f 6e 20 | 6f 66 20 66 69 6c 65 20 |version |of file |
|00001b50| 7b 5c 74 74 20 70 6f 73 | 69 78 2e 63 7d 7d 7d 0a |{\tt pos|ix.c}}}.|
|00001b60| 5c 6c 61 62 65 6c 7b 70 | 6f 73 69 78 2d 31 7d 0a |\label{p|osix-1}.|
|00001b70| 5c 76 73 6b 69 70 32 6d | 6d 5c 68 72 75 6c 65 5c |\vskip2m|m\hrule\|
|00001b80| 76 73 6b 69 70 33 6d 6d | 0a 5c 65 6e 64 7b 71 75 |vskip3mm|.\end{qu|
|00001b90| 6f 74 65 7d 0a 5c 65 6e | 64 7b 66 69 67 75 72 65 |ote}.\en|d{figure|
|00001ba0| 7d 20 0a 0a 5c 73 75 62 | 73 65 63 74 69 6f 6e 7b |} ..\sub|section{|
|00001bb0| 50 61 73 73 69 6e 67 20 | 61 72 67 75 6d 65 6e 74 |Passing |argument|
|00001bc0| 73 20 74 6f 20 61 20 70 | 72 69 6d 69 74 69 76 65 |s to a p|rimitive|
|00001bd0| 7d 0a 0a 54 68 69 73 20 | 73 65 63 74 69 6f 6e 20 |}..This |section |
|00001be0| 73 68 6f 77 73 20 68 6f | 77 20 74 6f 20 70 61 73 |shows ho|w to pas|
|00001bf0| 73 20 61 72 67 75 6d 65 | 6e 74 73 20 74 6f 20 61 |s argume|nts to a|
|00001c00| 20 6e 65 77 20 70 72 69 | 6d 69 74 69 76 65 20 77 | new pri|mitive w|
|00001c10| 72 69 74 74 65 6e 20 69 | 6e 0a 43 2e 20 54 6f 20 |ritten i|n.C. To |
|00001c20| 69 6c 6c 75 73 74 72 61 | 74 65 20 6f 75 72 20 70 |illustra|te our p|
|00001c30| 75 72 70 6f 73 65 2c 20 | 77 65 20 77 69 6c 6c 20 |urpose, |we will |
|00001c40| 72 65 77 72 69 74 65 20 | 74 68 65 20 70 72 69 6d |rewrite |the prim|
|00001c50| 69 74 69 76 65 20 7b 5c | 74 74 0a 70 6f 73 69 78 |itive {\|tt.posix|
|00001c60| 2d 63 74 69 6d 65 7d 20 | 74 6f 20 62 65 20 63 6f |-ctime} |to be co|
|00001c70| 6e 66 6f 72 6d 20 74 6f | 20 50 4f 53 49 58 2e 31 |nform to| POSIX.1|
|00001c80| 20 28 74 68 69 73 20 66 | 75 6e 63 74 69 6f 6e 20 | (this f|unction |
|00001c90| 73 68 6f 75 6c 64 20 74 | 61 6b 65 20 61 6e 0a 69 |should t|ake an.i|
|00001ca0| 6e 74 65 67 65 72 2c 20 | 61 20 63 6f 75 6e 74 20 |nteger, |a count |
|00001cb0| 6f 66 20 73 65 63 6f 6e | 64 73 2c 20 61 6e 64 20 |of secon|ds, and |
|00001cc0| 73 68 6f 75 6c 64 20 72 | 65 74 75 72 6e 20 63 6f |should r|eturn co|
|00001cd0| 72 72 65 73 70 6f 6e 64 | 69 6e 67 20 64 61 74 65 |rrespond|ing date|
|00001ce0| 20 61 73 20 61 0a 73 74 | 72 69 6e 67 29 2e 20 41 | as a.st|ring). A|
|00001cf0| 20 73 65 63 6f 6e 64 20 | 77 72 69 74 69 6e 67 20 | second |writing |
|00001d00| 6f 66 20 70 72 65 76 69 | 6f 75 73 20 66 75 6e 63 |of previ|ous func|
|00001d10| 74 69 6f 6e 20 63 6f 75 | 6c 64 20 62 65 3a 0a 0a |tion cou|ld be:..|
|00001d20| 5c 62 65 67 69 6e 7b 43 | 6f 64 65 7d 0a 5c 62 65 |\begin{C|ode}.\be|
|00001d30| 67 69 6e 7b 6c 69 73 74 | 69 6e 67 7d 5b 32 30 30 |gin{list|ing}[200|
|00001d40| 5d 7b 32 7d 0a 73 74 61 | 74 69 63 20 50 52 49 4d |]{2}.sta|tic PRIM|
|00001d50| 49 54 49 56 45 20 70 6f | 73 69 78 5f 63 74 69 6d |ITIVE po|six_ctim|
|00001d60| 65 28 53 43 4d 20 73 65 | 63 6f 6e 64 73 29 0a 7b |e(SCM se|conds).{|
|00001d70| 0a 20 20 6c 6f 6e 67 20 | 73 65 63 3b 0a 0a 20 20 |. long |sec;.. |
|00001d80| 73 65 63 20 3d 20 53 54 | 6b 5f 69 6e 74 65 67 65 |sec = ST|k_intege|
|00001d90| 72 5f 76 61 6c 75 65 5f | 6e 6f 5f 6f 76 65 72 66 |r_value_|no_overf|
|00001da0| 6c 6f 77 28 73 65 63 6f | 6e 64 73 29 3b 0a 20 20 |low(seco|nds);. |
|00001db0| 72 65 74 75 72 6e 20 53 | 54 6b 5f 6d 61 6b 65 73 |return S|Tk_makes|
|00001dc0| 74 72 69 6e 67 28 63 74 | 69 6d 65 28 28 74 69 6d |tring(ct|ime((tim|
|00001dd0| 65 5f 74 20 2a 29 26 73 | 65 63 29 29 3b 0a 7d 0a |e_t *)&s|ec));.}.|
|00001de0| 5c 65 6e 64 7b 6c 69 73 | 74 69 6e 67 7d 0a 5c 65 |\end{lis|ting}.\e|
|00001df0| 6e 64 7b 43 6f 64 65 7d | 0a 0a 0a 54 68 69 73 20 |nd{Code}|...This |
|00001e00| 66 75 6e 63 74 69 6f 6e | 20 68 61 73 20 6f 6e 65 |function| has one|
|00001e10| 20 70 61 72 61 6d 65 74 | 65 72 20 73 69 6e 63 65 | paramet|er since|
|00001e20| 20 53 63 68 65 6d 65 20 | 70 72 69 6d 69 74 69 76 | Scheme |primitiv|
|00001e30| 65 20 61 72 69 74 79 20 | 69 73 20 6f 6e 65 2e 20 |e arity |is one. |
|00001e40| 54 68 65 0a 43 20 70 72 | 69 6d 69 74 69 76 65 73 |The.C pr|imitives|
|00001e50| 20 70 61 72 61 6d 65 74 | 65 72 73 20 61 72 65 20 | paramet|ers are |
|00001e60| 61 6c 77 61 79 73 20 5c | 49 6e 64 65 78 74 74 7b |always \|Indextt{|
|00001e70| 53 43 4d 7d 20 6f 62 6a | 65 63 74 73 2e 20 41 6e |SCM} obj|ects. An|
|00001e80| 20 6f 62 6a 65 63 74 20 | 6f 66 20 74 68 69 73 20 | object |of this |
|00001e90| 74 79 70 65 20 69 73 0a | 61 20 70 6f 69 6e 74 65 |type is.|a pointe|
|00001ea0| 72 20 74 6f 20 61 20 5c | 49 6e 64 65 78 74 74 7b |r to a \|Indextt{|
|00001eb0| 73 74 72 75 63 74 20 6f | 62 6a 7d 3a 20 74 68 65 |struct o|bj}: the|
|00001ec0| 20 74 79 70 65 20 77 68 | 69 63 68 20 70 65 72 6d | type wh|ich perm|
|00001ed0| 69 74 73 20 74 6f 20 72 | 65 70 72 65 73 65 6e 74 |its to r|epresent|
|00001ee0| 20 61 6c 6c 20 74 68 65 | 0a 53 63 68 65 6d 65 20 | all the|.Scheme |
|00001ef0| 6f 62 6a 65 63 74 73 2e | 20 20 54 68 65 20 7b 5c |objects.| The {\|
|00001f00| 74 74 20 53 43 4d 7d 20 | 61 6e 64 20 7b 5c 74 74 |tt SCM} |and {\tt|
|00001f10| 20 73 74 72 75 63 74 7e | 6f 62 6a 7d 20 74 79 70 | struct~|obj} typ|
|00001f20| 65 73 20 64 65 66 69 6e | 69 74 69 6f 6e 73 20 63 |es defin|itions c|
|00001f30| 61 6e 0a 62 65 20 66 6f | 75 6e 64 20 69 6e 20 74 |an.be fo|und in t|
|00001f40| 68 65 20 5c 49 6e 64 65 | 78 74 74 7b 53 72 63 2f |he \Inde|xtt{Src/|
|00001f50| 73 74 6b 2e 68 7d 20 68 | 65 61 64 65 72 20 66 69 |stk.h} h|eader fi|
|00001f60| 6c 65 2e 20 0a 0a 54 68 | 65 20 66 69 72 73 74 20 |le. ..Th|e first |
|00001f70| 6a 6f 62 20 6f 66 20 74 | 68 69 73 20 66 75 6e 63 |job of t|his func|
|00001f80| 74 69 6f 6e 20 63 6f 6e | 73 69 73 74 73 20 74 6f |tion con|sists to|
|00001f90| 20 63 6f 6e 76 65 72 74 | 20 74 68 65 20 53 63 68 | convert| the Sch|
|00001fa0| 65 6d 65 0a 70 61 72 61 | 6d 65 74 65 72 20 28 7b |eme.para|meter ({|
|00001fb0| 5c 74 74 20 73 65 63 6f | 6e 64 73 7d 29 20 74 6f |\tt seco|nds}) to|
|00001fc0| 20 61 20 43 20 69 6e 74 | 65 67 65 72 20 7b 5c 74 | a C int|eger {\t|
|00001fd0| 74 20 6c 6f 6e 67 20 69 | 6e 74 7d 2e 20 54 68 69 |t long i|nt}. Thi|
|00001fe0| 73 20 69 73 20 64 6f 6e | 65 20 77 69 74 68 20 74 |s is don|e with t|
|00001ff0| 68 65 0a 66 75 6e 63 74 | 69 6f 6e 20 5c 49 6e 64 |he.funct|ion \Ind|
|00002000| 65 78 74 74 7b 53 54 6b | 5c 5f 69 6e 74 65 67 65 |extt{STk|\_intege|
|00002010| 72 5c 5f 76 61 6c 75 65 | 5c 5f 6e 6f 5c 5f 6f 76 |r\_value|\_no\_ov|
|00002020| 65 72 66 6c 6f 77 7d 77 | 68 69 63 68 20 74 61 6b |erflow}w|hich tak|
|00002030| 65 73 20 61 20 7b 5c 74 | 74 20 53 43 4d 7d 0a 61 |es a {\t|t SCM}.a|
|00002040| 6e 64 20 72 65 74 75 72 | 6e 73 20 61 20 7b 5c 74 |nd retur|ns a {\t|
|00002050| 74 20 6c 6f 6e 67 20 69 | 6e 74 7d 2e 20 54 68 69 |t long i|nt}. Thi|
|00002060| 73 20 66 75 6e 63 74 69 | 6f 6e 73 20 72 65 74 75 |s functi|ons retu|
|00002070| 72 6e 73 20 7b 5c 74 74 | 20 4c 4f 4e 47 5c 5f 4d |rns {\tt| LONG\_M|
|00002080| 49 4e 7d 20 69 66 0a 74 | 68 65 20 61 72 67 75 6d |IN} if.t|he argum|
|00002090| 65 6e 74 20 69 73 20 6e | 6f 74 20 61 20 61 6e 20 |ent is n|ot a an |
|000020a0| 69 6e 74 65 67 65 72 20 | 6e 75 6d 62 65 72 20 28 |integer |number (|
|000020b0| 6f 72 20 61 20 6e 75 6d | 62 65 72 20 77 68 69 63 |or a num|ber whic|
|000020c0| 68 20 64 6f 6e 27 74 20 | 66 69 74 20 69 6e 20 74 |h don't |fit in t|
|000020d0| 68 65 20 43 0a 72 65 70 | 72 65 73 65 6e 74 61 74 |he C.rep|resentat|
|000020e0| 69 6f 6e 20 6f 66 20 61 | 20 43 20 7b 5c 74 74 20 |ion of a| C {\tt |
|000020f0| 6c 6f 6e 67 20 69 6e 74 | 7d 29 2e 20 4f 6e 63 65 |long int|}). Once|
|00002100| 20 74 68 69 73 20 63 6f | 6e 76 65 72 73 69 6f 6e | this co|nversion|
|00002110| 20 69 73 20 64 6f 6e 65 | 2c 0a 74 68 65 20 72 65 | is done|,.the re|
|00002120| 73 74 20 6f 66 20 74 68 | 65 20 6a 6f 62 20 69 73 |st of th|e job is|
|00002130| 20 73 69 6d 69 6c 61 72 | 20 74 6f 20 74 68 65 20 | similar| to the |
|00002140| 63 6f 64 65 20 70 72 65 | 73 65 6e 74 65 64 20 61 |code pre|sented a|
|00002150| 62 6f 76 65 2e 0a 0a 54 | 6f 20 61 64 64 20 74 68 |bove...T|o add th|
|00002160| 69 73 20 70 72 69 6d 69 | 74 69 76 65 20 74 6f 20 |is primi|tive to |
|00002170| 74 68 65 20 67 6c 6f 62 | 61 6c 20 53 63 68 65 6d |the glob|al Schem|
|00002180| 65 20 65 6e 76 69 72 6f | 6e 6d 65 6e 74 2c 20 77 |e enviro|nment, w|
|00002190| 65 20 68 61 76 65 20 74 | 6f 0a 63 68 61 6e 67 65 |e have t|o.change|
|000021a0| 20 74 68 65 20 70 72 65 | 76 69 6f 75 73 20 7b 5c | the pre|vious {\|
|000021b0| 74 74 20 53 54 6b 5c 5f | 61 64 64 5c 5f 6e 65 77 |tt STk\_|add\_new|
|000021c0| 5c 5f 70 72 69 6d 69 74 | 69 76 65 7d 20 66 6f 72 |\_primit|ive} for|
|000021d0| 20 74 68 69 73 20 70 72 | 69 6d 69 74 69 76 65 20 | this pr|imitive |
|000021e0| 62 79 3a 0a 0a 5c 62 65 | 67 69 6e 7b 43 6f 64 65 |by:..\be|gin{Code|
|000021f0| 7d 0a 5c 62 65 67 69 6e | 7b 6c 69 73 74 69 6e 67 |}.\begin|{listing|
|00002200| 7d 5b 32 30 30 5d 7b 32 | 7d 0a 53 54 6b 5f 61 64 |}[200]{2|}.STk_ad|
|00002210| 64 5f 6e 65 77 5f 70 72 | 69 6d 69 74 69 76 65 28 |d_new_pr|imitive(|
|00002220| 22 70 6f 73 69 78 2d 63 | 74 69 6d 65 22 2c 20 74 |"posix-c|time", t|
|00002230| 63 5f 73 75 62 72 5f 31 | 2c 20 70 6f 73 69 78 5f |c_subr_1|, posix_|
|00002240| 63 74 69 6d 65 29 3b 0a | 5c 65 6e 64 7b 6c 69 73 |ctime);.|\end{lis|
|00002250| 74 69 6e 67 7d 0a 5c 65 | 6e 64 7b 43 6f 64 65 7d |ting}.\e|nd{Code}|
|00002260| 0a 0a 69 6e 20 74 68 65 | 20 69 6e 69 74 20 73 65 |..in the| init se|
|00002270| 63 74 69 6f 6e 2e 20 54 | 68 69 73 20 63 61 6c 6c |ction. T|his call|
|00002280| 20 73 74 61 74 65 73 20 | 74 68 61 74 20 74 68 65 | states |that the|
|00002290| 20 74 79 70 65 20 6f 66 | 20 74 68 69 73 20 70 72 | type of| this pr|
|000022a0| 69 6d 69 74 69 76 65 0a | 69 73 20 66 69 78 65 64 |imitive.|is fixed|
|000022b0| 20 74 6f 20 61 20 5c 49 | 6e 64 65 78 74 74 7b 74 | to a \I|ndextt{t|
|000022c0| 63 5c 5f 73 75 62 72 5c | 5f 31 7d 20 28 61 20 61 |c\_subr\|_1} (a a|
|000022d0| 72 69 74 79 2d 31 20 70 | 72 69 6d 69 74 69 76 65 |rity-1 p|rimitive|
|000022e0| 29 2e 0a 0a 48 6f 77 65 | 76 65 72 2c 20 74 68 69 |)...Howe|ver, thi|
|000022f0| 73 20 66 75 6e 63 74 69 | 6f 6e 20 69 73 20 6e 6f |s functi|on is no|
|00002300| 74 20 74 6f 6f 20 73 61 | 74 69 73 66 79 69 6e 67 |t too sa|tisfying|
|00002310| 2c 20 65 76 65 6e 20 69 | 66 20 63 6c 6f 73 65 20 |, even i|f close |
|00002320| 74 6f 20 74 68 65 0a 50 | 4f 53 49 58 20 64 65 66 |to the.P|OSIX def|
|00002330| 69 6e 69 74 69 6f 6e 3a | 20 69 74 20 6f 62 6c 69 |inition:| it obli|
|00002340| 67 65 73 20 74 6f 20 70 | 61 73 73 20 61 20 70 61 |ges to p|ass a pa|
|00002350| 72 61 6d 65 74 65 72 20 | 77 68 69 63 68 20 77 69 |rameter |which wi|
|00002360| 6c 6c 20 62 65 0a 70 72 | 6f 62 61 62 6c 79 20 6d |ll be.pr|obably m|
|00002370| 6f 73 74 20 6f 66 20 74 | 68 65 20 74 69 6d 65 20 |ost of t|he time |
|00002380| 74 68 65 20 72 65 73 75 | 6c 74 20 6f 66 20 74 68 |the resu|lt of th|
|00002390| 65 20 70 72 69 6d 69 74 | 69 76 65 20 7b 5c 74 74 |e primit|ive {\tt|
|000023a0| 0a 70 6f 73 69 78 2d 74 | 69 6d 65 7d 20 28 69 2e |.posix-t|ime} (i.|
|000023b0| 65 2e 20 74 68 65 20 6d | 6f 73 74 20 66 72 65 71 |e. the m|ost freq|
|000023c0| 75 65 6e 74 20 75 73 61 | 67 65 20 6f 66 20 74 68 |uent usa|ge of th|
|000023d0| 69 73 20 66 75 6e 63 74 | 69 6f 6e 20 77 69 6c 6c |is funct|ion will|
|000023e0| 20 62 65 0a 0a 5c 62 65 | 67 69 6e 7b 43 6f 64 65 | be..\be|gin{Code|
|000023f0| 7d 0a 5c 62 65 67 69 6e | 7b 6c 69 73 74 69 6e 67 |}.\begin|{listing|
|00002400| 7d 5b 32 30 30 5d 7b 32 | 7d 0a 28 70 6f 73 69 78 |}[200]{2|}.(posix|
|00002410| 2d 63 74 69 6d 65 20 28 | 70 6f 73 69 78 2d 74 69 |-ctime (|posix-ti|
|00002420| 6d 65 29 29 0a 5c 65 6e | 64 7b 6c 69 73 74 69 6e |me)).\en|d{listin|
|00002430| 67 7d 0a 5c 65 6e 64 7b | 43 6f 64 65 7d 0a 0a 77 |g}.\end{|Code}..w|
|00002440| 68 69 63 68 20 69 73 20 | 6e 6f 74 20 76 65 72 79 |hich is |not very|
|00002450| 20 65 6c 65 67 61 6e 74 | 29 2e 20 41 20 62 65 74 | elegant|). A bet|
|00002460| 74 65 72 20 61 70 70 72 | 6f 61 63 68 20 63 6f 6e |ter appr|oach con|
|00002470| 73 69 73 74 73 20 74 6f | 20 61 6c 6c 6f 77 20 74 |sists to| allow t|
|00002480| 68 69 73 0a 70 72 69 6d | 69 74 69 76 65 20 74 6f |his.prim|itive to|
|00002490| 20 68 61 76 65 20 61 20 | 6f 70 74 69 6f 6e 61 6c | have a |optional|
|000024a0| 20 70 61 72 61 6d 65 74 | 65 72 2e 20 54 68 69 73 | paramet|er. This|
|000024b0| 20 70 65 72 6d 69 74 73 | 20 74 6f 20 62 65 20 61 | permits| to be a|
|000024c0| 74 20 74 68 65 0a 73 61 | 6d 65 20 74 69 6d 65 20 |t the.sa|me time |
|000024d0| 63 6f 6e 66 6f 72 6d 20 | 74 6f 20 74 68 65 20 50 |conform |to the P|
|000024e0| 4f 53 49 58 20 63 6f 6e | 76 65 6e 74 69 6f 6e 20 |OSIX con|vention |
|000024f0| 61 6e 64 20 63 6c 6f 73 | 65 20 74 6f 20 53 63 68 |and clos|e to Sch|
|00002500| 65 6d 65 20 68 61 62 69 | 74 73 2e 20 0a 54 68 65 |eme habi|ts. .The|
|00002510| 20 66 6f 6c 6c 6f 77 69 | 6e 67 20 76 65 72 73 69 | followi|ng versi|
|00002520| 6f 6e 20 69 6d 70 6c 65 | 6d 65 6e 74 73 20 74 68 |on imple|ments th|
|00002530| 65 20 7b 5c 74 74 20 70 | 6f 73 69 78 2d 63 74 69 |e {\tt p|osix-cti|
|00002540| 6d 65 7d 20 77 69 74 68 | 20 61 20 6f 70 74 69 6f |me} with| a optio|
|00002550| 6e 61 6c 0a 70 61 72 61 | 6d 65 74 65 72 3a 0a 5c |nal.para|meter:.\|
|00002560| 62 65 67 69 6e 7b 43 6f | 64 65 7d 0a 5c 62 65 67 |begin{Co|de}.\beg|
|00002570| 69 6e 7b 6c 69 73 74 69 | 6e 67 7d 5b 32 30 30 5d |in{listi|ng}[200]|
|00002580| 7b 32 7d 0a 73 74 61 74 | 69 63 20 50 52 49 4d 49 |{2}.stat|ic PRIMI|
|00002590| 54 49 56 45 20 70 6f 73 | 69 78 5f 63 74 69 6d 65 |TIVE pos|ix_ctime|
|000025a0| 28 53 43 4d 20 73 65 63 | 6f 6e 64 73 29 0a 7b 0a |(SCM sec|onds).{.|
|000025b0| 20 20 6c 6f 6e 67 20 73 | 65 63 3b 0a 0a 20 20 73 | long s|ec;.. s|
|000025c0| 65 63 20 3d 20 28 73 65 | 63 6f 6e 64 73 3d 3d 55 |ec = (se|conds==U|
|000025d0| 4e 42 4f 55 4e 44 29 20 | 3f 20 74 69 6d 65 28 4e |NBOUND) |? time(N|
|000025e0| 55 4c 4c 29 0a 20 20 20 | 20 20 20 20 20 20 20 20 |ULL). | |
|000025f0| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|00002600| 3a 20 53 54 6b 5f 69 6e | 74 65 67 65 72 5f 76 61 |: STk_in|teger_va|
|00002610| 6c 75 65 5f 6e 6f 5f 6f | 76 65 72 66 6c 6f 77 28 |lue_no_o|verflow(|
|00002620| 73 65 63 6f 6e 64 73 29 | 3b 0a 20 20 72 65 74 75 |seconds)|;. retu|
|00002630| 72 6e 20 53 54 6b 5f 6d | 61 6b 65 73 74 72 69 6e |rn STk_m|akestrin|
|00002640| 67 28 63 74 69 6d 65 28 | 28 74 69 6d 65 5f 74 20 |g(ctime(|(time_t |
|00002650| 2a 29 20 26 73 65 63 29 | 29 3b 0a 7d 0a 5c 65 6e |*) &sec)|);.}.\en|
|00002660| 64 7b 6c 69 73 74 69 6e | 67 7d 0a 5c 65 6e 64 7b |d{listin|g}.\end{|
|00002670| 43 6f 64 65 7d 0a 0a 49 | 66 20 74 68 65 20 53 63 |Code}..I|f the Sc|
|00002680| 68 65 6d 65 20 7b 5c 74 | 74 20 70 6f 73 69 78 2d |heme {\t|t posix-|
|00002690| 63 74 69 6d 65 7d 20 70 | 72 69 6d 69 74 69 76 65 |ctime} p|rimitive|
|000026a0| 20 69 73 20 63 61 6c 6c | 65 64 20 77 69 74 68 20 | is call|ed with |
|000026b0| 6f 6e 65 20 70 61 72 61 | 6d 65 74 65 72 2c 20 69 |one para|meter, i|
|000026c0| 74 0a 77 69 6c 6c 20 62 | 65 20 70 61 73 73 65 64 |t.will b|e passed|
|000026d0| 20 74 6f 20 74 68 65 20 | 43 20 66 75 6e 63 74 69 | to the |C functi|
|000026e0| 6f 6e 20 69 6e 20 74 68 | 65 20 7b 5c 74 74 20 73 |on in th|e {\tt s|
|000026f0| 65 63 6f 6e 64 73 7d 20 | 70 61 72 61 6d 65 74 65 |econds} |paramete|
|00002700| 72 2e 20 49 66 20 7b 5c | 74 74 0a 70 6f 73 69 78 |r. If {\|tt.posix|
|00002710| 2d 63 74 69 6d 65 7d 20 | 69 73 20 63 61 6c 6c 65 |-ctime} |is calle|
|00002720| 64 20 77 69 74 68 6f 75 | 74 20 70 61 72 61 6d 65 |d withou|t parame|
|00002730| 74 65 72 2c 20 7b 5c 74 | 74 20 73 65 63 6f 6e 64 |ter, {\t|t second|
|00002740| 73 7d 20 69 73 20 73 65 | 74 20 74 6f 20 74 68 65 |s} is se|t to the|
|00002750| 20 73 70 65 63 69 61 6c | 0a 76 61 6c 75 65 20 5c | special|.value \|
|00002760| 49 6e 64 65 78 74 74 7b | 55 4e 42 4f 55 4e 44 7d |Indextt{|UNBOUND}|
|00002770| 2e 20 53 6f 2c 20 74 68 | 65 20 66 69 72 73 74 20 |. So, th|e first |
|00002780| 74 65 73 74 20 69 6e 20 | 74 68 69 73 20 66 75 6e |test in |this fun|
|00002790| 63 74 69 6f 6e 20 63 6f | 6e 73 69 73 74 73 20 74 |ction co|nsists t|
|000027a0| 6f 20 73 65 74 20 61 0a | 63 6f 72 72 65 63 74 20 |o set a.|correct |
|000027b0| 76 61 6c 75 65 20 74 6f | 20 74 68 65 20 76 61 72 |value to| the var|
|000027c0| 69 61 62 6c 65 20 7b 5c | 74 74 20 73 65 63 7d 3b |iable {\|tt sec};|
|000027d0| 20 74 68 69 73 20 76 61 | 6c 75 65 20 69 73 20 65 | this va|lue is e|
|000027e0| 69 74 68 65 72 20 74 68 | 65 20 63 75 72 72 65 6e |ither th|e curren|
|000027f0| 74 0a 74 69 6d 65 2c 20 | 65 69 74 68 65 72 20 74 |t.time, |either t|
|00002800| 68 65 20 67 69 76 65 6e | 20 69 6e 74 65 67 65 72 |he given| integer|
|00002810| 2c 20 64 65 70 65 6e 64 | 69 6e 67 20 6f 66 20 74 |, depend|ing of t|
|00002820| 68 65 20 6e 75 6d 62 65 | 72 20 6f 66 20 70 61 72 |he numbe|r of par|
|00002830| 61 6d 65 74 65 72 73 0a | 67 69 76 65 6e 20 74 6f |ameters.|given to|
|00002840| 20 7b 5c 74 74 20 70 6f | 73 69 78 2d 63 74 69 6d | {\tt po|six-ctim|
|00002850| 65 7d 2e 0a 0a 4f 66 20 | 63 6f 75 72 73 65 2c 20 |e}...Of |course, |
|00002860| 74 68 65 20 74 79 70 65 | 20 6f 66 20 74 68 69 73 |the type| of this|
|00002870| 20 6e 65 77 20 70 72 69 | 6d 69 74 69 76 65 20 6d | new pri|mitive m|
|00002880| 75 73 74 20 62 65 20 63 | 68 61 6e 67 65 64 20 74 |ust be c|hanged t|
|00002890| 6f 20 61 6c 6c 6f 77 20 | 30 20 6f 72 20 31 0a 70 |o allow |0 or 1.p|
|000028a0| 61 72 61 6d 65 74 65 72 | 2e 20 54 68 69 73 20 69 |arameter|. This i|
|000028b0| 73 20 64 6f 6e 65 20 62 | 79 20 63 68 61 6e 67 69 |s done b|y changi|
|000028c0| 6e 67 20 74 68 65 20 7b | 5c 74 74 20 74 63 5c 5f |ng the {|\tt tc\_|
|000028d0| 73 75 62 72 5c 5f 30 7d | 20 69 6e 20 74 68 65 20 |subr\_0}| in the |
|000028e0| 70 72 65 76 69 6f 75 73 | 20 0a 7b 5c 74 74 20 53 |previous| .{\tt S|
|000028f0| 54 6b 5c 5f 61 64 64 5c | 5f 6e 65 77 5c 5f 70 72 |Tk\_add\|_new\_pr|
|00002900| 69 6d 69 74 69 76 65 7d | 20 62 79 20 5c 49 6e 64 |imitive}| by \Ind|
|00002910| 65 78 74 74 7b 74 63 5c | 5f 73 75 62 72 5c 5f 30 |extt{tc\|_subr\_0|
|00002920| 5c 5f 6f 72 5c 5f 31 7d | 2e 0a 0a 54 68 65 20 66 |\_or\_1}|...The f|
|00002930| 6f 6c 6c 6f 77 69 6e 67 | 20 74 79 70 65 73 20 61 |ollowing| types a|
|00002940| 72 65 20 61 76 61 69 6c | 61 62 6c 65 20 66 6f 72 |re avail|able for|
|00002950| 20 43 20 70 72 69 6d 69 | 74 69 76 65 73 3a 0a 5c | C primi|tives:.\|
|00002960| 62 65 67 69 6e 7b 69 74 | 65 6d 69 7a 65 7d 0a 5c |begin{it|emize}.\|
|00002970| 69 74 65 6d 20 5c 49 6e | 64 65 78 74 74 7b 74 63 |item \In|dextt{tc|
|00002980| 5c 5f 73 75 62 72 5c 5f | 30 7d 20 66 6f 72 20 61 |\_subr\_|0} for a|
|00002990| 72 69 74 79 2d 30 20 70 | 72 69 6d 69 74 69 76 65 |rity-0 p|rimitive|
|000029a0| 73 0a 5c 69 74 65 6d 20 | 5c 49 6e 64 65 78 74 74 |s.\item |\Indextt|
|000029b0| 7b 74 63 5c 5f 73 75 62 | 72 5c 5f 31 7d 20 66 6f |{tc\_sub|r\_1} fo|
|000029c0| 72 20 61 72 69 74 79 2d | 31 20 70 72 69 6d 69 74 |r arity-|1 primit|
|000029d0| 69 76 65 73 0a 5c 69 74 | 65 6d 20 5c 49 6e 64 65 |ives.\it|em \Inde|
|000029e0| 78 74 74 7b 74 63 5c 5f | 73 75 62 72 5c 5f 32 7d |xtt{tc\_|subr\_2}|
|000029f0| 20 66 6f 72 20 61 72 69 | 74 79 2d 32 20 70 72 69 | for ari|ty-2 pri|
|00002a00| 6d 69 74 69 76 65 73 0a | 5c 69 74 65 6d 20 5c 49 |mitives.|\item \I|
|00002a10| 6e 64 65 78 74 74 7b 74 | 63 5c 5f 73 75 62 72 5c |ndextt{t|c\_subr\|
|00002a20| 5f 33 7d 20 66 6f 72 20 | 61 72 69 74 79 2d 33 20 |_3} for |arity-3 |
|00002a30| 70 72 69 6d 69 74 69 76 | 65 73 0a 5c 69 74 65 6d |primitiv|es.\item|
|00002a40| 20 5c 49 6e 64 65 78 74 | 74 7b 74 63 5c 5f 73 75 | \Indext|t{tc\_su|
|00002a50| 62 72 5c 5f 30 5c 5f 6f | 72 5c 5f 31 7d 20 66 6f |br\_0\_o|r\_1} fo|
|00002a60| 72 20 70 72 69 6d 69 74 | 69 76 65 73 20 0a 20 20 |r primit|ives . |
|00002a70| 20 20 20 20 77 68 69 63 | 68 20 68 61 76 65 20 30 | whic|h have 0|
|00002a80| 20 6f 72 20 31 20 70 61 | 72 61 6d 65 74 65 72 0a | or 1 pa|rameter.|
|00002a90| 20 20 20 20 20 20 28 65 | 2e 67 2e 7e 7b 5c 74 74 | (e|.g.~{\tt|
|00002aa0| 20 72 65 61 64 7d 29 2e | 20 4f 6e 20 74 68 65 20 | read}).| On the |
|00002ab0| 43 20 73 69 64 65 20 79 | 6f 75 20 68 61 76 65 20 |C side y|ou have |
|00002ac0| 74 6f 20 64 65 63 6c 61 | 72 65 20 61 20 66 75 6e |to decla|re a fun|
|00002ad0| 63 74 69 6f 6e 0a 20 20 | 20 20 20 20 77 68 69 63 |ction. | whic|
|00002ae0| 68 20 74 61 6b 65 73 20 | 6f 6e 65 20 7b 5c 74 74 |h takes |one {\tt|
|00002af0| 20 53 43 4d 7d 20 61 72 | 67 75 6d 65 6e 74 2e 20 | SCM} ar|gument. |
|00002b00| 54 68 69 73 20 61 72 67 | 75 6d 65 6e 74 20 69 73 |This arg|ument is|
|00002b10| 20 73 65 74 20 74 6f 20 | 74 68 65 0a 20 20 20 20 | set to |the. |
|00002b20| 20 20 28 65 76 61 6c 75 | 61 74 65 64 29 20 70 61 | (evalu|ated) pa|
|00002b30| 72 61 6d 65 74 65 72 20 | 69 66 20 70 72 65 73 65 |rameter |if prese|
|00002b40| 6e 74 2c 20 74 6f 20 7b | 5c 74 74 20 55 4e 42 4f |nt, to {|\tt UNBO|
|00002b50| 55 4e 44 7d 20 6f 74 68 | 65 72 77 69 73 65 2e 0a |UND} oth|erwise..|
|00002b60| 5c 69 74 65 6d 20 5c 49 | 6e 64 65 78 74 74 7b 74 |\item \I|ndextt{t|
|00002b70| 63 5c 5f 73 75 62 72 5c | 5f 31 5c 5f 6f 72 5c 5f |c\_subr\|_1\_or\_|
|00002b80| 32 7d 20 66 6f 72 20 0a | 20 20 20 20 20 20 70 72 |2} for .| pr|
|00002b90| 69 6d 69 74 69 76 65 73 | 20 77 68 69 63 68 20 68 |imitives| which h|
|00002ba0| 61 76 65 20 31 20 6f 72 | 20 32 20 70 61 72 61 6d |ave 1 or| 2 param|
|00002bb0| 65 74 65 72 73 0a 20 20 | 20 20 20 20 28 65 2e 67 |eters. | (e.g|
|00002bc0| 2e 7e 7b 5c 74 74 20 77 | 72 69 74 65 7d 29 2e 20 |.~{\tt w|rite}). |
|00002bd0| 48 65 72 65 20 79 6f 75 | 20 68 61 76 65 20 74 6f |Here you| have to|
|00002be0| 20 64 65 63 6c 61 72 65 | 20 61 20 43 20 66 75 6e | declare| a C fun|
|00002bf0| 63 74 69 6f 6e 20 77 69 | 74 68 0a 20 20 20 20 20 |ction wi|th. |
|00002c00| 20 74 77 6f 20 7b 5c 74 | 74 20 53 43 4d 7d 20 70 | two {\t|t SCM} p|
|00002c10| 61 72 61 6d 65 74 65 72 | 73 2e 20 54 68 65 20 66 |arameter|s. The f|
|00002c20| 69 72 73 74 20 6f 6e 65 | 20 77 69 6c 6c 20 63 6f |irst one| will co|
|00002c30| 6e 74 61 69 6e 20 74 68 | 65 20 66 69 72 73 74 20 |ntain th|e first |
|00002c40| 53 63 68 65 6d 65 20 0a | 20 20 20 20 20 20 61 72 |Scheme .| ar|
|00002c50| 67 75 6d 65 6e 74 20 61 | 6e 64 20 74 68 65 20 73 |gument a|nd the s|
|00002c60| 65 63 6f 6e 64 20 77 69 | 6c 6c 20 63 6f 6e 74 61 |econd wi|ll conta|
|00002c70| 69 6e 20 74 68 65 20 73 | 65 63 6f 6e 64 20 61 72 |in the s|econd ar|
|00002c80| 67 75 6d 65 6e 74 20 76 | 61 6c 75 65 0a 20 20 20 |gument v|alue. |
|00002c90| 20 20 20 6f 72 20 7b 5c | 74 74 20 55 4e 42 4f 55 | or {\|tt UNBOU|
|00002ca0| 4e 44 7d 20 69 66 20 6f | 6d 69 74 74 65 64 2e 0a |ND} if o|mitted..|
|00002cb0| 5c 69 74 65 6d 20 5c 49 | 6e 64 65 78 74 74 7b 74 |\item \I|ndextt{t|
|00002cc0| 63 5c 5f 73 75 62 72 5c | 5f 32 5c 5f 6f 72 5c 5f |c\_subr\|_2\_or\_|
|00002cd0| 33 7d 20 66 6f 72 20 0a | 20 20 20 20 20 20 70 72 |3} for .| pr|
|00002ce0| 69 6d 69 74 69 76 65 73 | 20 77 68 69 63 68 20 68 |imitives| which h|
|00002cf0| 61 76 65 20 32 20 6f 72 | 20 33 20 70 61 72 61 6d |ave 2 or| 3 param|
|00002d00| 65 74 65 72 73 0a 20 20 | 20 20 20 20 28 74 68 65 |eters. | (the|
|00002d10| 72 65 27 73 20 6e 6f 20 | 70 72 69 6d 69 74 69 76 |re's no |primitiv|
|00002d20| 65 20 6f 66 20 74 68 69 | 73 20 74 79 70 65 20 69 |e of thi|s type i|
|00002d30| 6e 20 63 6f 72 65 20 69 | 6e 74 65 72 70 72 65 74 |n core i|nterpret|
|00002d40| 65 72 29 2e 0a 20 20 20 | 20 20 20 4f 66 20 63 6f |er).. | Of co|
|00002d50| 75 72 73 65 2c 20 79 6f | 75 27 6c 6c 20 68 61 76 |urse, yo|u'll hav|
|00002d60| 65 20 74 6f 20 64 65 63 | 6c 61 72 65 20 61 20 43 |e to dec|lare a C|
|00002d70| 20 66 75 6e 63 74 69 6f | 6e 20 77 69 74 68 20 74 | functio|n with t|
|00002d80| 68 72 65 65 20 7b 5c 74 | 74 20 53 43 4d 7d 0a 20 |hree {\t|t SCM}. |
|00002d90| 20 20 20 20 20 70 61 72 | 61 6d 65 74 65 72 73 2e | par|ameters.|
|00002da0| 20 41 70 61 72 74 20 74 | 68 61 74 2c 20 63 6f 6e | Apart t|hat, con|
|00002db0| 76 65 6e 74 69 6f 6e 73 | 20 61 72 65 20 74 68 65 |ventions| are the|
|00002dc0| 20 73 61 6d 65 20 68 61 | 73 20 62 65 66 6f 72 65 | same ha|s before|
|00002dd0| 2e 0a 5c 69 74 65 6d 20 | 5c 49 6e 64 65 78 74 74 |..\item |\Indextt|
|00002de0| 7b 74 63 5c 5f 6c 73 75 | 62 72 7d 20 66 6f 72 20 |{tc\_lsu|br} for |
|00002df0| 70 72 69 6d 69 74 69 76 | 65 73 20 77 68 69 63 68 |primitiv|es which|
|00002e00| 20 68 61 76 65 20 61 20 | 76 61 72 69 61 62 6c 65 | have a |variable|
|00002e10| 20 6e 75 6d 62 65 72 20 | 6f 66 0a 20 20 20 20 20 | number |of. |
|00002e20| 20 61 72 67 75 6d 65 6e | 74 73 2e 20 41 63 74 75 | argumen|ts. Actu|
|00002e30| 61 6c 73 20 61 72 67 75 | 6d 65 6e 74 73 20 61 72 |als argu|ments ar|
|00002e40| 65 20 63 6f 6c 6c 65 63 | 74 65 64 20 69 6e 20 61 |e collec|ted in a|
|00002e50| 20 6c 69 73 74 20 77 68 | 69 63 68 20 69 73 20 67 | list wh|ich is g|
|00002e60| 69 76 65 6e 20 61 73 20 | 74 68 65 0a 20 20 20 20 |iven as |the. |
|00002e70| 20 20 66 69 72 73 74 20 | 61 72 67 75 6d 65 6e 74 | first |argument|
|00002e80| 20 6f 66 20 74 68 65 20 | 43 20 70 72 69 6d 69 74 | of the |C primit|
|00002e90| 69 76 65 2e 20 54 68 65 | 20 73 65 63 6f 6e 64 20 |ive. The| second |
|00002ea0| 61 72 67 75 6d 65 6e 74 | 20 6f 66 20 74 68 65 20 |argument| of the |
|00002eb0| 43 20 66 75 6e 63 74 69 | 6f 6e 0a 20 20 20 20 20 |C functi|on. |
|00002ec0| 20 69 73 20 61 6e 20 69 | 6e 74 65 67 65 72 20 63 | is an i|nteger c|
|00002ed0| 6f 75 6e 74 69 6e 67 20 | 74 68 65 20 61 63 74 75 |ounting |the actu|
|00002ee0| 61 6c 20 6e 75 6d 62 65 | 72 20 6f 66 20 61 72 67 |al numbe|r of arg|
|00002ef0| 75 6d 65 6e 74 73 20 67 | 69 76 65 6e 20 74 6f 20 |uments g|iven to |
|00002f00| 74 68 65 0a 20 20 20 20 | 20 20 70 72 69 6d 69 74 |the. | primit|
|00002f10| 69 76 65 2e 20 48 65 6e | 63 65 2c 20 74 68 65 20 |ive. Hen|ce, the |
|00002f20| 73 69 67 6e 61 74 75 72 | 65 20 6f 66 20 74 68 65 |signatur|e of the|
|00002f30| 20 43 20 66 75 6e 63 74 | 69 6f 6e 20 77 68 69 63 | C funct|ion whic|
|00002f40| 68 20 69 6d 70 6c 65 6d | 65 6e 74 20 61 20 7b 5c |h implem|ent a {\|
|00002f50| 74 74 0a 20 20 20 20 20 | 20 74 63 5c 5f 6c 73 75 |tt. | tc\_lsu|
|00002f60| 62 72 7d 20 6d 75 73 74 | 20 62 65 0a 5c 62 65 67 |br} must| be.\beg|
|00002f70| 69 6e 7b 71 75 6f 74 65 | 7d 0a 5c 62 65 67 69 6e |in{quote|}.\begin|
|00002f80| 7b 76 65 72 62 61 74 69 | 6d 7d 0a 50 52 49 4d 49 |{verbati|m}.PRIMI|
|00002f90| 54 49 56 45 20 66 75 6e | 63 74 69 6f 6e 28 53 43 |TIVE fun|ction(SC|
|00002fa0| 4d 20 61 72 67 6c 69 73 | 74 2c 20 69 6e 74 20 61 |M arglis|t, int a|
|00002fb0| 72 67 63 6f 75 6e 74 29 | 3b 0a 5c 65 6e 64 7b 76 |rgcount)|;.\end{v|
|00002fc0| 65 72 62 61 74 69 6d 7d | 0a 5c 65 6e 64 7b 71 75 |erbatim}|.\end{qu|
|00002fd0| 6f 74 65 7d 0a 20 20 20 | 20 20 20 4e 6f 74 65 20 |ote}. | Note |
|00002fe0| 74 68 61 74 20 61 6c 6c | 20 74 68 65 20 53 63 68 |that all| the Sch|
|00002ff0| 65 6d 65 20 61 72 67 75 | 6d 65 6e 74 73 20 61 72 |eme argu|ments ar|
|00003000| 65 20 65 76 61 6c 75 61 | 74 65 64 20 64 75 72 69 |e evalua|ted duri|
|00003010| 6e 67 20 74 68 65 0a 20 | 20 20 20 20 20 63 6f 6e |ng the. | con|
|00003020| 73 74 72 75 63 74 69 6f | 6e 20 6f 66 20 74 68 65 |structio|n of the|
|00003030| 20 6c 69 73 74 20 77 68 | 69 63 68 20 69 73 20 70 | list wh|ich is p|
|00003040| 61 73 73 65 64 20 74 6f | 20 74 68 65 20 43 20 66 |assed to| the C f|
|00003050| 75 6e 63 74 69 6f 6e 2e | 0a 5c 69 74 65 6d 20 5c |unction.|.\item \|
|00003060| 49 6e 64 65 78 74 74 7b | 74 63 5c 5f 66 73 75 62 |Indextt{|tc\_fsub|
|00003070| 72 7d 20 69 73 20 73 69 | 6d 69 6c 61 72 20 74 6f |r} is si|milar to|
|00003080| 20 7b 5c 74 74 20 74 63 | 5c 5f 6c 73 75 62 72 7d | {\tt tc|\_lsubr}|
|00003090| 20 65 78 63 65 70 74 20 | 74 68 61 74 0a 20 20 20 | except |that. |
|000030a0| 20 20 20 61 72 67 75 6d | 65 6e 74 73 20 61 72 65 | argum|ents are|
|000030b0| 20 6e 6f 74 20 65 76 61 | 6c 75 61 74 65 64 2e 20 | not eva|luated. |
|000030c0| 4f 6e 20 74 68 65 20 43 | 20 73 69 64 65 2c 20 79 |On the C| side, y|
|000030d0| 6f 75 20 68 61 76 65 20 | 74 6f 20 64 65 63 6c 61 |ou have |to decla|
|000030e0| 72 65 20 61 20 66 75 6e | 63 74 69 6f 6e 0a 20 20 |re a fun|ction. |
|000030f0| 20 20 20 20 77 69 74 68 | 20 74 68 72 65 65 20 7b | with| three {|
|00003100| 5c 74 74 20 53 43 4d 7d | 20 70 61 72 61 6d 65 74 |\tt SCM}| paramet|
|00003110| 65 72 73 3a 20 74 68 65 | 20 6c 69 73 74 20 6f 66 |ers: the| list of|
|00003120| 20 28 6e 6f 6e 20 65 76 | 61 6c 75 61 74 65 64 29 | (non ev|aluated)|
|00003130| 20 61 72 67 75 6d 65 6e | 74 73 2c 0a 20 20 20 20 | argumen|ts,. |
|00003140| 20 20 74 68 65 20 63 75 | 72 72 65 6e 74 20 65 6e | the cu|rrent en|
|00003150| 76 69 72 6f 6e 6d 65 6e | 74 20 61 6e 64 20 74 68 |vironmen|t and th|
|00003160| 65 20 6c 65 6e 67 74 68 | 20 6f 66 20 74 68 65 20 |e length| of the |
|00003170| 61 72 67 75 6d 65 6e 74 | 73 20 6c 69 73 74 2e 20 |argument|s list. |
|00003180| 54 68 65 0a 20 20 20 20 | 20 20 73 69 67 6e 61 74 |The. | signat|
|00003190| 75 72 65 20 6f 66 20 74 | 68 65 20 43 20 66 75 6e |ure of t|he C fun|
|000031a0| 63 74 69 6f 6e 20 77 68 | 69 63 68 20 69 6d 70 6c |ction wh|ich impl|
|000031b0| 65 6d 65 6e 74 20 61 20 | 7b 5c 74 74 20 74 63 5c |ement a |{\tt tc\|
|000031c0| 5f 66 73 75 62 72 7d 20 | 6d 75 73 74 20 62 65 0a |_fsubr} |must be.|
|000031d0| 5c 62 65 67 69 6e 7b 71 | 75 6f 74 65 7d 0a 5c 62 |\begin{q|uote}.\b|
|000031e0| 65 67 69 6e 7b 76 65 72 | 62 61 74 69 6d 7d 0a 50 |egin{ver|batim}.P|
|000031f0| 52 49 4d 49 54 49 56 45 | 20 66 75 6e 63 74 69 6f |RIMITIVE| functio|
|00003200| 6e 28 53 43 4d 20 61 72 | 67 6c 69 73 74 2c 20 53 |n(SCM ar|glist, S|
|00003210| 43 4d 20 65 6e 76 2c 20 | 69 6e 74 20 61 72 67 63 |CM env, |int argc|
|00003220| 6f 75 6e 74 29 3b 0a 5c | 65 6e 64 7b 76 65 72 62 |ount);.\|end{verb|
|00003230| 61 74 69 6d 7d 0a 5c 65 | 6e 64 7b 71 75 6f 74 65 |atim}.\e|nd{quote|
|00003240| 7d 0a 20 20 20 20 20 20 | 53 65 65 20 5c 72 65 66 |}. |See \ref|
|00003250| 7b 65 76 61 6c 75 61 74 | 69 6e 67 2d 61 72 67 73 |{evaluat|ing-args|
|00003260| 7d 20 6d 6f 72 65 20 64 | 65 74 61 69 6c 73 20 61 |} more d|etails a|
|00003270| 62 6f 75 74 20 7b 5c 74 | 74 20 74 63 5c 5f 66 73 |bout {\t|t tc\_fs|
|00003280| 75 62 72 7d 2e 0a 0a 5c | 69 74 65 6d 20 7b 5c 74 |ubr}...\|item {\t|
|00003290| 74 20 74 63 5c 5f 74 6b | 63 6f 6d 6d 61 6e 64 7d |t tc\_tk|command}|
|000032a0| 20 66 6f 72 20 70 72 69 | 6d 69 74 69 76 65 73 20 | for pri|mitives |
|000032b0| 77 68 69 63 68 20 66 6f | 6c 6c 6f 77 20 20 74 68 |which fo|llow th|
|000032c0| 65 20 54 63 6c 0a 20 20 | 20 20 20 20 63 6f 6d 6d |e Tcl. | comm|
|000032d0| 61 6e 64 20 61 72 67 75 | 6d 65 6e 74 20 70 61 73 |and argu|ment pas|
|000032e0| 73 69 6e 67 20 73 74 79 | 6c 65 20 28 69 2e 65 2e |sing sty|le (i.e.|
|000032f0| 7e 7b 5c 65 6d 20 5c 60 | 61 20 6c 61 7d 20 7b 5c |~{\em \`|a la} {\|
|00003300| 74 74 20 61 72 67 63 2f | 61 72 67 76 7d 29 2e 20 |tt argc/|argv}). |
|00003310| 54 68 69 73 0a 20 20 20 | 20 20 20 69 73 20 74 68 |This. | is th|
|00003320| 69 73 20 6b 69 6e 64 20 | 6f 66 20 70 72 6f 63 65 |is kind |of proce|
|00003330| 64 75 72 65 20 74 68 61 | 74 20 77 69 6c 6c 20 62 |dure tha|t will b|
|00003340| 65 20 75 73 65 64 20 66 | 6f 72 20 74 6f 20 61 64 |e used f|or to ad|
|00003350| 64 20 6e 65 77 20 77 69 | 64 67 65 74 73 20 69 6e |d new wi|dgets in|
|00003360| 20 74 68 65 0a 20 20 20 | 20 20 20 7b 5c 73 74 6b | the. | {\stk|
|00003370| 7d 20 69 6e 74 65 72 70 | 72 65 74 65 72 2e 20 53 |} interp|reter. S|
|00003380| 65 65 20 5c 72 65 66 7b | 6e 65 77 2d 77 69 64 67 |ee \ref{|new-widg|
|00003390| 65 74 7d 20 61 6e 64 20 | 5c 63 69 74 65 7b 6f 75 |et} and |\cite{ou|
|000033a0| 73 74 65 72 2d 62 6f 6f | 6b 7d 20 66 6f 72 20 6d |ster-boo|k} for m|
|000033b0| 6f 72 65 0a 20 20 20 20 | 20 20 64 65 74 61 69 6c |ore. | detail|
|000033c0| 73 2e 0a 5c 65 6e 64 7b | 69 74 65 6d 69 7a 65 7d |s..\end{|itemize}|
|000033d0| 0a 0a 54 6f 20 69 6c 6c | 75 73 74 72 61 74 65 20 |..To ill|ustrate |
|000033e0| 68 6f 77 20 74 6f 20 77 | 72 69 74 65 20 61 20 7b |how to w|rite a {|
|000033f0| 5c 74 74 20 74 63 5c 5f | 6c 73 75 62 72 7d 20 70 |\tt tc\_|lsubr} p|
|00003400| 72 69 6d 69 74 69 76 65 | 2c 20 6c 65 74 27 73 20 |rimitive|, let's |
|00003410| 68 61 76 65 20 61 20 6c | 6f 6f 6b 20 61 74 20 74 |have a l|ook at t|
|00003420| 68 65 0a 63 6f 64 65 2c | 20 67 69 76 65 6e 20 62 |he.code,| given b|
|00003430| 65 6c 6f 77 2c 20 6f 66 | 20 74 68 65 20 66 75 6e |elow, of| the fun|
|00003440| 63 74 69 6f 6e 20 77 68 | 69 63 68 20 69 6d 70 6c |ction wh|ich impl|
|00003450| 65 6d 65 6e 74 20 74 68 | 65 20 53 63 68 65 6d 65 |ement th|e Scheme|
|00003460| 20 70 72 69 6d 69 74 69 | 76 65 20 7b 5c 74 74 0a | primiti|ve {\tt.|
|00003470| 76 65 63 74 6f 72 7d 3a | 0a 5c 62 65 67 69 6e 7b |vector}:|.\begin{|
|00003480| 71 75 6f 74 65 7d 7b 5c | 73 6d 61 6c 6c 0a 5c 62 |quote}{\|small.\b|
|00003490| 65 67 69 6e 7b 76 65 72 | 62 61 74 69 6d 7d 0a 50 |egin{ver|batim}.P|
|000034a0| 52 49 4d 49 54 49 56 45 | 20 53 54 6b 5f 76 65 63 |RIMITIVE| STk_vec|
|000034b0| 74 6f 72 28 53 43 4d 20 | 61 72 67 6c 69 73 74 2c |tor(SCM |arglist,|
|000034c0| 20 69 6e 74 20 61 72 67 | 63 6f 75 6e 74 29 0a 7b | int arg|count).{|
|000034d0| 0a 20 20 69 6e 74 20 6a | 3b 0a 20 20 53 43 4d 20 |. int j|;. SCM |
|000034e0| 7a 20 3d 20 53 54 6b 5f | 6d 61 6b 65 76 65 63 74 |z = STk_|makevect|
|000034f0| 28 61 72 67 63 6f 75 6e | 74 2c 20 4e 55 4c 4c 29 |(argcoun|t, NULL)|
|00003500| 3b 0a 20 20 0a 20 20 66 | 6f 72 20 28 6a 20 3d 20 |;. . f|or (j = |
|00003510| 30 3b 20 6a 20 3c 20 61 | 72 67 63 6f 75 6e 74 3b |0; j < a|rgcount;|
|00003520| 20 6a 2b 2b 2c 20 61 72 | 67 6c 69 73 74 3d 43 44 | j++, ar|glist=CD|
|00003530| 52 28 61 72 67 6c 69 73 | 74 29 29 20 7b 0a 20 20 |R(arglis|t)) {. |
|00003540| 20 20 56 45 43 54 28 7a | 29 5b 6a 5d 20 3d 20 43 | VECT(z|)[j] = C|
|00003550| 41 52 28 61 72 67 6c 69 | 73 74 29 3b 0a 20 20 7d |AR(argli|st);. }|
|00003560| 0a 20 20 72 65 74 75 72 | 6e 20 7a 3b 0a 7d 0a 5c |. retur|n z;.}.\|
|00003570| 65 6e 64 7b 76 65 72 62 | 61 74 69 6d 7d 0a 7d 5c |end{verb|atim}.}\|
|00003580| 65 6e 64 7b 71 75 6f 74 | 65 7d 0a 0a 54 68 69 73 |end{quot|e}..This|
|00003590| 20 66 75 6e 63 74 69 6f | 6e 20 72 65 63 65 69 76 | functio|n receiv|
|000035a0| 65 73 20 74 68 65 20 76 | 61 6c 75 65 73 20 70 61 |es the v|alues pa|
|000035b0| 73 73 65 64 20 74 6f 20 | 74 68 65 20 7b 5c 74 74 |ssed to |the {\tt|
|000035c0| 20 76 65 63 74 6f 72 7d | 20 70 72 69 6d 69 74 69 | vector}| primiti|
|000035d0| 76 65 73 20 69 6e 20 74 | 68 65 0a 6c 69 73 74 20 |ves in t|he.list |
|000035e0| 61 72 67 6c 69 73 74 20 | 28 74 68 65 20 6c 65 6e |arglist |(the len|
|000035f0| 67 74 68 20 6f 66 20 74 | 68 69 73 20 6c 69 73 74 |gth of t|his list|
|00003600| 20 69 73 20 73 74 6f 72 | 65 64 20 69 6e 20 7b 5c | is stor|ed in {\|
|00003610| 74 74 20 61 72 67 63 6f | 75 6e 74 7d 29 2e 20 54 |tt argco|unt}). T|
|00003620| 68 69 73 0a 66 75 6e 63 | 74 69 6f 6e 20 75 73 65 |his.func|tion use|
|00003630| 73 20 5c 49 6e 64 65 78 | 74 74 7b 53 54 6b 5c 5f |s \Index|tt{STk\_|
|00003640| 6d 61 6b 65 76 65 63 74 | 7d 20 77 68 69 63 68 20 |makevect|} which |
|00003650| 72 65 74 75 72 6e 73 20 | 61 20 53 63 68 65 6d 65 |returns |a Scheme|
|00003660| 20 76 65 63 74 6f 72 2e | 20 49 74 73 20 66 69 72 | vector.| Its fir|
|00003670| 73 74 0a 61 72 67 75 6d | 65 6e 74 20 69 73 20 74 |st.argum|ent is t|
|00003680| 68 65 20 6c 65 6e 67 74 | 68 20 6f 66 20 74 68 65 |he lengt|h of the|
|00003690| 20 76 65 63 74 6f 72 20 | 61 6e 64 20 69 74 73 20 | vector |and its |
|000036a0| 73 65 63 6f 6e 64 20 61 | 72 67 75 6d 65 6e 74 20 |second a|rgument |
|000036b0| 69 73 20 74 68 65 20 69 | 6e 69 74 69 61 6c 0a 76 |is the i|nitial.v|
|000036c0| 61 6c 75 65 20 6f 66 20 | 74 68 65 20 76 65 63 74 |alue of |the vect|
|000036d0| 6f 72 27 73 20 65 6c 65 | 6d 65 6e 74 73 2e 20 20 |or's ele|ments. |
|000036e0| 4e 65 78 74 20 73 65 63 | 74 69 6f 6e 20 77 69 6c |Next sec|tion wil|
|000036f0| 6c 20 73 68 6f 77 20 68 | 6f 77 20 74 6f 20 69 6d |l show h|ow to im|
|00003700| 70 6c 65 6d 65 6e 74 20 | 61 0a 70 72 69 6d 69 74 |plement |a.primit|
|00003710| 69 76 65 20 77 68 69 63 | 68 20 65 76 61 6c 75 61 |ive whic|h evalua|
|00003720| 74 65 73 20 69 74 73 65 | 6c 66 20 69 74 73 20 70 |tes itse|lf its p|
|00003730| 61 72 61 6d 65 74 65 72 | 73 20 28 69 2e 65 2e 20 |arameter|s (i.e. |
|00003740| 61 20 7b 5c 74 74 20 74 | 63 5c 5f 66 73 75 62 72 |a {\tt t|c\_fsubr|
|00003750| 7d 0a 70 72 69 6d 69 74 | 69 76 65 2e 0a 0a 5c 73 |}.primit|ive...\s|
|00003760| 75 62 73 65 63 74 69 6f | 6e 7b 45 76 61 6c 75 61 |ubsectio|n{Evalua|
|00003770| 74 69 6e 67 20 61 72 67 | 75 6d 65 6e 74 73 7d 0a |ting arg|uments}.|
|00003780| 0a 49 6e 20 73 6f 6d 65 | 20 63 69 72 63 75 6d 73 |.In some| circums|
|00003790| 74 61 6e 63 65 73 20 69 | 74 20 63 6f 75 6c 64 20 |tances i|t could |
|000037a0| 62 65 20 75 73 65 66 75 | 6c 20 74 6f 20 61 64 64 |be usefu|l to add|
|000037b0| 20 6e 65 77 20 70 72 69 | 6d 69 74 69 76 65 73 20 | new pri|mitives |
|000037c0| 77 68 69 63 68 20 64 6f | 6e 27 74 0a 65 76 61 6c |which do|n't.eval|
|000037d0| 75 61 74 65 20 74 68 65 | 69 72 20 61 72 67 75 6d |uate the|ir argum|
|000037e0| 65 6e 74 73 2e 20 54 68 | 69 73 20 70 65 72 6d 69 |ents. Th|is permi|
|000037f0| 74 73 20 74 6f 20 61 64 | 64 20 6e 65 77 20 63 6f |ts to ad|d new co|
|00003800| 6e 74 72 6f 6c 20 73 74 | 72 75 63 74 75 72 65 73 |ntrol st|ructures|
|00003810| 20 74 6f 20 74 68 65 0a | 69 6e 74 65 72 70 72 65 | to the.|interpre|
|00003820| 74 65 72 2e 20 54 6f 20 | 69 6c 6c 75 73 74 72 61 |ter. To |illustra|
|00003830| 74 65 20 74 68 69 73 2c | 20 77 65 20 77 69 6c 6c |te this,| we will|
|00003840| 20 61 64 64 20 74 77 6f | 20 6e 65 77 20 70 72 69 | add two| new pri|
|00003850| 6d 69 74 69 76 65 73 20 | 74 6f 20 74 68 65 20 7b |mitives |to the {|
|00003860| 5c 73 74 6b 7d 0a 69 6e | 74 65 72 70 72 65 74 65 |\stk}.in|terprete|
|00003870| 72 3a 20 7b 5c 74 74 20 | 77 68 65 6e 7d 20 61 6e |r: {\tt |when} an|
|00003880| 64 20 7b 5c 74 74 20 75 | 6e 6c 65 73 73 7d 2e 20 |d {\tt u|nless}. |
|00003890| 41 73 20 65 78 70 6c 61 | 69 6e 65 64 20 69 6e 20 |As expla|ined in |
|000038a0| 74 68 65 20 70 72 65 63 | 65 64 69 6e 67 0a 73 65 |the prec|eding.se|
|000038b0| 63 74 69 6f 6e 2c 20 74 | 68 65 20 43 20 66 75 6e |ction, t|he C fun|
|000038c0| 63 74 69 6f 6e 73 20 77 | 68 69 63 68 20 77 69 6c |ctions w|hich wil|
|000038d0| 6c 20 69 6d 70 6c 65 6d | 65 6e 74 20 74 68 6f 73 |l implem|ent thos|
|000038e0| 65 20 63 6f 6e 74 72 6f | 6c 20 73 74 72 75 63 74 |e contro|l struct|
|000038f0| 75 72 65 73 20 6d 75 73 | 74 20 62 65 0a 6f 66 20 |ures mus|t be.of |
|00003900| 74 79 70 65 20 5c 49 6e | 64 65 78 74 74 7b 74 63 |type \In|dextt{tc|
|00003910| 5c 5f 66 73 75 62 72 7d | 2e 20 41 20 7b 5c 74 74 |\_fsubr}|. A {\tt|
|00003920| 20 74 63 5c 5f 66 73 75 | 62 72 7d 20 70 72 69 6d | tc\_fsu|br} prim|
|00003930| 69 74 69 76 65 2c 20 6f | 6e 20 74 68 65 20 43 0a |itive, o|n the C.|
|00003940| 73 69 64 65 2c 20 69 73 | 20 67 69 76 65 6e 20 74 |side, is| given t|
|00003950| 68 72 65 65 20 70 61 72 | 61 6d 65 74 65 72 73 20 |hree par|ameters |
|00003960| 77 68 65 6e 20 63 61 6c | 6c 65 64 3a 20 0a 5c 62 |when cal|led: .\b|
|00003970| 65 67 69 6e 7b 65 6e 75 | 6d 65 72 61 74 65 7d 0a |egin{enu|merate}.|
|00003980| 5c 69 74 65 6d 20 61 20 | 6c 69 73 74 20 6f 66 20 |\item a |list of |
|00003990| 69 74 73 20 28 6e 6f 6e | 20 65 76 61 6c 75 61 74 |its (non| evaluat|
|000039a0| 65 64 29 20 70 61 72 61 | 6d 65 74 65 72 73 2c 20 |ed) para|meters, |
|000039b0| 0a 5c 69 74 65 6d 20 74 | 68 65 20 6c 6f 63 61 6c |.\item t|he local|
|000039c0| 20 65 6e 76 69 72 6f 6e | 6d 65 6e 74 20 77 68 65 | environ|ment whe|
|000039d0| 6e 20 69 74 20 77 61 73 | 20 63 61 6c 6c 65 64 20 |n it was| called |
|000039e0| 28 61 6e 64 20 69 6e 20 | 77 68 69 63 68 0a 65 76 |(and in |which.ev|
|000039f0| 61 6c 75 61 74 69 6f 6e | 73 20 73 68 6f 75 6c 64 |aluation|s should|
|00003a00| 20 67 65 6e 65 72 61 6c | 6c 79 20 74 61 6b 65 20 | general|ly take |
|00003a10| 70 6c 61 63 65 29 2c 0a | 5c 69 74 65 6d 20 74 68 |place),.|\item th|
|00003a20| 65 20 6c 65 6e 67 74 68 | 20 6f 66 20 74 68 65 20 |e length| of the |
|00003a30| 70 61 72 61 6d 65 74 65 | 72 73 20 6c 69 73 74 2e |paramete|rs list.|
|00003a40| 0a 5c 65 6e 64 7b 65 6e | 75 6d 65 72 61 74 65 7d |.\end{en|umerate}|
|00003a50| 0a 0a 54 68 65 20 43 20 | 66 75 6e 63 74 69 6f 6e |..The C |function|
|00003a60| 20 63 61 6e 20 73 74 65 | 70 20 74 68 72 6f 75 67 | can ste|p throug|
|00003a70| 68 20 69 74 73 20 70 61 | 72 61 6d 65 74 65 72 20 |h its pa|rameter |
|00003a80| 6c 69 73 74 20 75 73 69 | 6e 67 20 74 68 65 20 43 |list usi|ng the C|
|00003a90| 20 6d 61 63 72 6f 73 0a | 7b 5c 74 74 20 43 41 52 | macros.|{\tt CAR|
|00003aa0| 7d 2c 20 7b 5c 74 74 20 | 43 44 52 7d 20 61 6e 64 |}, {\tt |CDR} and|
|00003ab0| 20 7b 5c 74 74 20 4e 55 | 4c 4c 50 7d 20 28 77 68 | {\tt NU|LLP} (wh|
|00003ac0| 69 63 68 20 64 6f 20 74 | 68 65 20 6f 62 76 69 6f |ich do t|he obvio|
|00003ad0| 75 73 20 77 6f 72 6b 29 | 20 61 6e 64 20 65 76 61 |us work)| and eva|
|00003ae0| 6c 75 61 74 65 73 20 65 | 6c 65 6d 65 6e 74 73 0a |luates e|lements.|
|00003af0| 6f 66 20 74 68 69 73 20 | 6c 69 73 74 20 61 73 20 |of this |list as |
|00003b00| 6e 65 65 64 65 64 2e 20 | 45 76 61 6c 75 61 74 69 |needed. |Evaluati|
|00003b10| 6f 6e 20 6f 66 20 61 6e | 20 65 78 70 72 65 73 73 |on of an| express|
|00003b20| 69 6f 6e 20 63 61 6e 20 | 62 65 20 64 6f 6e 65 20 |ion can |be done |
|00003b30| 77 69 74 68 0a 74 68 65 | 20 5c 49 6e 64 65 78 74 |with.the| \Indext|
|00003b40| 74 7b 53 54 6b 5c 5f 65 | 76 61 6c 7d 20 43 20 66 |t{STk\_e|val} C f|
|00003b50| 75 6e 63 74 69 6f 6e 2e | 20 7b 5c 74 74 20 53 54 |unction.| {\tt ST|
|00003b60| 6b 5c 5f 65 76 61 6c 7d | 20 74 61 6b 65 73 20 74 |k\_eval}| takes t|
|00003b70| 77 6f 20 70 61 72 61 6d | 65 74 65 72 73 3a 20 74 |wo param|eters: t|
|00003b80| 68 65 0a 65 78 70 72 65 | 73 73 69 6f 6e 20 74 6f |he.expre|ssion to|
|00003b90| 20 65 76 61 6c 75 61 74 | 65 20 61 6e 64 20 74 68 | evaluat|e and th|
|00003ba0| 65 20 65 6e 76 69 72 6f | 6e 6d 65 6e 74 20 69 6e |e enviro|nment in|
|00003bb0| 20 77 68 69 63 68 20 65 | 76 61 6c 75 61 74 69 6f | which e|valuatio|
|00003bc0| 6e 20 74 61 6b 65 73 0a | 70 6c 61 63 65 20 28 74 |n takes.|place (t|
|00003bd0| 68 65 20 5c 49 6e 64 65 | 78 74 74 7b 4e 49 4c 7d |he \Inde|xtt{NIL}|
|00003be0| 20 76 61 72 69 61 62 6c | 65 2c 20 62 79 20 63 6f | variabl|e, by co|
|00003bf0| 6e 76 65 6e 74 69 6f 6e | 2c 20 64 65 6e 6f 74 65 |nvention|, denote|
|00003c00| 73 20 74 68 65 20 49 6e | 64 65 78 7b 67 6c 6f 62 |s the In|dex{glob|
|00003c10| 61 6c 20 65 6e 76 69 72 | 6f 6e 6d 65 6e 74 7d 29 |al envir|onment})|
|00003c20| 2e 0a 0a 5c 70 61 72 61 | 67 72 61 70 68 2a 7b 4e |...\para|graph*{N|
|00003c30| 6f 74 65 3a 7d 20 7b 5c | 62 66 20 61 20 6c 69 73 |ote:} {\|bf a lis|
|00003c40| 74 20 6f 66 20 61 72 67 | 75 6d 65 6e 74 73 20 69 |t of arg|uments i|
|00003c50| 73 20 61 6c 77 61 79 73 | 20 61 20 70 72 6f 70 65 |s always| a prope|
|00003c60| 72 20 6c 69 73 74 2e 20 | 59 6f 75 20 64 6f 6e 27 |r list. |You don'|
|00003c70| 74 20 6e 65 65 64 20 74 | 6f 20 74 65 73 74 0a 69 |t need t|o test.i|
|00003c80| 66 20 69 74 20 69 73 20 | 77 65 6c 6c 20 66 6f 72 |f it is |well for|
|00003c90| 6d 65 64 2e 7d 0a 0a 48 | 65 72 65 61 66 74 65 72 |med.}..H|ereafter|
|00003ca0| 20 69 73 20 74 68 65 20 | 63 6f 64 65 20 6f 66 20 | is the |code of |
|00003cb0| 74 68 65 20 7b 5c 74 74 | 20 77 68 65 6e 7d 20 70 |the {\tt| when} p|
|00003cc0| 72 69 6d 69 74 69 76 65 | 2e 0a 5c 62 65 67 69 6e |rimitive|..\begin|
|00003cd0| 7b 43 6f 64 65 7d 0a 5c | 62 65 67 69 6e 7b 6c 69 |{Code}.\|begin{li|
|00003ce0| 73 74 69 6e 67 7d 5b 32 | 30 30 5d 7b 32 7d 0a 73 |sting}[2|00]{2}.s|
|00003cf0| 74 61 74 69 63 20 50 52 | 49 4d 49 54 49 56 45 20 |tatic PR|IMITIVE |
|00003d00| 77 68 65 6e 28 53 43 4d | 20 6c 2c 20 53 43 4d 20 |when(SCM| l, SCM |
|00003d10| 65 6e 76 2c 20 69 6e 74 | 20 61 72 67 63 6f 75 6e |env, int| argcoun|
|00003d20| 74 29 0a 7b 0a 20 20 53 | 43 4d 20 72 65 73 20 3d |t).{. S|CM res =|
|00003d30| 20 55 4e 44 45 46 49 4e | 45 44 3b 0a 0a 20 20 69 | UNDEFIN|ED;.. i|
|00003d40| 66 20 28 61 72 67 63 6f | 75 6e 74 20 3e 20 31 29 |f (argco|unt > 1)|
|00003d50| 20 7b 0a 20 20 20 20 69 | 66 20 28 53 54 6b 5f 65 | {. i|f (STk_e|
|00003d60| 76 61 6c 28 43 41 52 28 | 6c 29 2c 20 65 6e 76 29 |val(CAR(|l), env)|
|00003d70| 20 21 3d 20 4e 74 72 75 | 74 68 29 20 7b 0a 20 20 | != Ntru|th) {. |
|00003d80| 20 20 20 20 66 6f 72 20 | 28 6c 20 3d 20 43 44 52 | for |(l = CDR|
|00003d90| 28 6c 29 3b 20 21 4e 55 | 4c 4c 50 28 6c 29 3b 20 |(l); !NU|LLP(l); |
|00003da0| 6c 20 3d 20 43 44 52 28 | 6c 29 29 20 7b 0a 20 20 |l = CDR(|l)) {. |
|00003db0| 20 20 20 20 20 20 72 65 | 73 20 3d 20 53 54 6b 5f | re|s = STk_|
|00003dc0| 65 76 61 6c 28 43 41 52 | 28 6c 29 2c 20 65 6e 76 |eval(CAR|(l), env|
|00003dd0| 29 3b 0a 20 20 20 20 20 | 20 7d 0a 20 20 20 20 7d |);. | }. }|
|00003de0| 0a 20 20 7d 0a 20 20 72 | 65 74 75 72 6e 20 72 65 |. }. r|eturn re|
|00003df0| 73 3b 0a 7d 0a 5c 65 6e | 64 7b 6c 69 73 74 69 6e |s;.}.\en|d{listin|
|00003e00| 67 7d 0a 5c 65 6e 64 7b | 43 6f 64 65 7d 0a 0a 5c |g}.\end{|Code}..\|
|00003e10| 6e 6f 69 6e 64 65 6e 74 | 0a 53 6f 6d 65 20 70 6f |noindent|.Some po|
|00003e20| 69 6e 74 73 20 74 6f 20 | 6e 6f 74 65 20 68 65 72 |ints to |note her|
|00003e30| 65 3a 0a 5c 62 65 67 69 | 6e 7b 69 74 65 6d 69 7a |e:.\begi|n{itemiz|
|00003e40| 65 7d 0a 5c 69 74 65 6d | 20 5c 49 6e 64 65 78 74 |e}.\item| \Indext|
|00003e50| 74 7b 55 4e 44 45 46 49 | 4e 45 44 7d 20 69 73 20 |t{UNDEFI|NED} is |
|00003e60| 61 6e 20 69 6e 74 65 72 | 70 72 65 74 65 72 20 7b |an inter|preter {|
|00003e70| 5c 65 6d 20 63 6f 6e 73 | 74 61 6e 74 7d 2e 20 49 |\em cons|tant}. I|
|00003e80| 74 20 73 65 72 76 65 73 | 20 74 6f 20 64 65 6e 6f |t serves| to deno|
|00003e90| 74 65 0a 74 68 65 20 6e | 6f 74 69 6f 6e 20 6f 66 |te.the n|otion of|
|00003ea0| 20 7b 5c 65 6d 20 60 60 | 5c 49 6e 64 65 78 7b 75 | {\em ``|\Index{u|
|00003eb0| 6e 73 70 65 63 69 66 69 | 65 64 20 72 65 73 75 6c |nspecifi|ed resul|
|00003ec0| 74 7d 27 27 7d 20 6f 66 | 20 7b 5c 72 72 72 72 7d |t}''} of| {\rrrr}|
|00003ed0| 2e 0a 5c 69 74 65 6d 20 | 5c 49 6e 64 65 78 74 74 |..\item |\Indextt|
|00003ee0| 7b 54 72 75 74 68 7d 20 | 61 6e 64 20 5c 49 6e 64 |{Truth} |and \Ind|
|00003ef0| 65 78 74 74 7b 4e 74 72 | 75 74 68 7d 20 61 72 65 |extt{Ntr|uth} are|
|00003f00| 20 74 77 6f 20 67 6c 6f | 62 61 6c 20 7b 5c 65 6d | two glo|bal {\em|
|00003f10| 20 63 6f 6e 73 74 61 6e | 74 73 7d 20 6f 66 20 74 | constan|ts} of t|
|00003f20| 68 65 0a 69 6e 74 65 72 | 70 72 65 74 65 72 20 77 |he.inter|preter w|
|00003f30| 68 69 63 68 20 64 65 6e | 6f 74 65 20 72 65 73 70 |hich den|ote resp|
|00003f40| 65 63 74 69 76 65 6c 79 | 20 74 68 65 20 5c 49 6e |ectively| the \In|
|00003f50| 64 65 78 74 74 7b 5c 23 | 74 7d 20 61 6e 64 20 5c |dextt{\#|t} and \|
|00003f60| 49 6e 64 65 78 74 74 7b | 5c 23 66 7d 20 53 63 68 |Indextt{|\#f} Sch|
|00003f70| 65 6d 65 0a 63 6f 6e 73 | 74 61 6e 74 73 2e 0a 5c |eme.cons|tants..\|
|00003f80| 65 6e 64 7b 69 74 65 6d | 69 7a 65 7d 0a 0a 5c 6e |end{item|ize}..\n|
|00003f90| 6f 69 6e 64 65 6e 74 0a | 46 69 67 75 72 65 7e 5c |oindent.|Figure~\|
|00003fa0| 72 65 66 7b 77 68 65 6e | 7d 20 73 68 6f 77 73 20 |ref{when|} shows |
|00003fb0| 61 20 63 6f 6d 70 6c 65 | 74 65 20 69 6d 70 6c 65 |a comple|te imple|
|00003fc0| 6d 65 6e 74 61 74 69 6f | 6e 20 6f 66 20 7b 5c 74 |mentatio|n of {\t|
|00003fd0| 74 20 77 68 65 6e 7d 20 | 61 6e 64 20 7b 5c 74 74 |t when} |and {\tt|
|00003fe0| 20 75 6e 6c 65 73 73 7d | 2e 0a 0a 5c 62 65 67 69 | unless}|...\begi|
|00003ff0| 6e 7b 66 69 67 75 72 65 | 7d 0a 5c 62 65 67 69 6e |n{figure|}.\begin|
|00004000| 7b 71 75 6f 74 65 7d 5c | 66 6f 6f 74 6e 6f 74 65 |{quote}\|footnote|
|00004010| 73 69 7a 65 0a 5c 62 65 | 67 69 6e 7b 76 65 72 62 |size.\be|gin{verb|
|00004020| 61 74 69 6d 7d 0a 23 69 | 6e 63 6c 75 64 65 20 3c |atim}.#i|nclude <|
|00004030| 73 74 6b 2e 68 3e 0a 0a | 73 74 61 74 69 63 20 50 |stk.h>..|static P|
|00004040| 52 49 4d 49 54 49 56 45 | 20 77 68 65 6e 28 53 43 |RIMITIVE| when(SC|
|00004050| 4d 20 6c 2c 20 53 43 4d | 20 65 6e 76 2c 20 69 6e |M l, SCM| env, in|
|00004060| 74 20 61 72 67 63 6f 75 | 6e 74 29 0a 7b 0a 20 20 |t argcou|nt).{. |
|00004070| 53 43 4d 20 72 65 73 20 | 3d 20 55 4e 44 45 46 49 |SCM res |= UNDEFI|
|00004080| 4e 45 44 3b 0a 0a 20 20 | 69 66 20 28 61 72 67 63 |NED;.. |if (argc|
|00004090| 6f 75 6e 74 20 3e 20 31 | 29 20 7b 0a 20 20 20 20 |ount > 1|) {. |
|000040a0| 69 66 20 28 53 54 6b 5f | 65 76 61 6c 28 43 41 52 |if (STk_|eval(CAR|
|000040b0| 28 6c 29 2c 20 65 6e 76 | 29 20 21 3d 20 4e 74 72 |(l), env|) != Ntr|
|000040c0| 75 74 68 29 20 7b 0a 20 | 20 20 20 20 20 66 6f 72 |uth) {. | for|
|000040d0| 20 28 6c 20 3d 20 43 44 | 52 28 6c 29 3b 20 21 4e | (l = CD|R(l); !N|
|000040e0| 55 4c 4c 50 28 6c 29 3b | 20 6c 20 3d 20 43 44 52 |ULLP(l);| l = CDR|
|000040f0| 28 6c 29 29 20 7b 0a 20 | 20 20 20 20 20 20 20 72 |(l)) {. | r|
|00004100| 65 73 20 3d 20 53 54 6b | 5f 65 76 61 6c 28 43 41 |es = STk|_eval(CA|
|00004110| 52 28 6c 29 2c 20 65 6e | 76 29 3b 0a 20 20 20 20 |R(l), en|v);. |
|00004120| 20 20 7d 0a 20 20 20 20 | 7d 0a 20 20 7d 0a 20 20 | }. |}. }. |
|00004130| 72 65 74 75 72 6e 20 72 | 65 73 3b 0a 7d 0a 0a 73 |return r|es;.}..s|
|00004140| 74 61 74 69 63 20 50 52 | 49 4d 49 54 49 56 45 20 |tatic PR|IMITIVE |
|00004150| 75 6e 6c 65 73 73 28 53 | 43 4d 20 6c 2c 20 53 43 |unless(S|CM l, SC|
|00004160| 4d 20 65 6e 76 2c 20 69 | 6e 74 20 61 72 67 63 6f |M env, i|nt argco|
|00004170| 75 6e 74 29 0a 7b 0a 20 | 20 53 43 4d 20 72 65 73 |unt).{. | SCM res|
|00004180| 20 3d 20 55 4e 44 45 46 | 49 4e 45 44 3b 0a 0a 20 | = UNDEF|INED;.. |
|00004190| 20 69 66 20 28 61 72 67 | 63 6f 75 6e 74 20 3e 20 | if (arg|count > |
|000041a0| 31 29 20 7b 0a 20 20 20 | 20 69 66 20 28 53 54 6b |1) {. | if (STk|
|000041b0| 5f 65 76 61 6c 28 43 41 | 52 28 6c 29 2c 20 65 6e |_eval(CA|R(l), en|
|000041c0| 76 29 20 3d 3d 20 4e 74 | 72 75 74 68 29 20 7b 0a |v) == Nt|ruth) {.|
|000041d0| 20 20 20 20 20 20 66 6f | 72 20 28 6c 20 3d 20 43 | fo|r (l = C|
|000041e0| 44 52 28 6c 29 3b 20 21 | 4e 55 4c 4c 50 28 6c 29 |DR(l); !|NULLP(l)|
|000041f0| 3b 20 6c 20 3d 20 43 44 | 52 28 6c 29 29 20 7b 0a |; l = CD|R(l)) {.|
|00004200| 20 20 20 20 20 20 20 20 | 72 65 73 20 3d 20 53 54 | |res = ST|
|00004210| 6b 5f 65 76 61 6c 28 43 | 41 52 28 6c 29 2c 20 65 |k_eval(C|AR(l), e|
|00004220| 6e 76 29 3b 0a 20 20 20 | 20 20 20 7d 0a 20 20 20 |nv);. | }. |
|00004230| 20 7d 0a 20 20 7d 0a 20 | 20 72 65 74 75 72 6e 20 | }. }. | return |
|00004240| 72 65 73 3b 0a 7d 0a 0a | 50 52 49 4d 49 54 49 56 |res;.}..|PRIMITIV|
|00004250| 45 20 53 54 6b 5f 69 6e | 69 74 5f 77 68 65 6e 5f |E STk_in|it_when_|
|00004260| 75 6e 6c 65 73 73 28 76 | 6f 69 64 29 0a 7b 0a 20 |unless(v|oid).{. |
|00004270| 20 61 64 64 5f 6e 65 77 | 5f 70 72 69 6d 69 74 69 | add_new|_primiti|
|00004280| 76 65 28 22 77 68 65 6e | 22 2c 20 20 20 20 20 20 |ve("when|", |
|00004290| 20 20 74 63 5f 66 73 75 | 62 72 2c 20 77 68 65 6e | tc_fsu|br, when|
|000042a0| 29 3b 0a 20 20 61 64 64 | 5f 6e 65 77 5f 70 72 69 |);. add|_new_pri|
|000042b0| 6d 69 74 69 76 65 28 22 | 75 6e 6c 65 73 73 22 2c |mitive("|unless",|
|000042c0| 20 20 20 20 20 20 74 63 | 5f 66 73 75 62 72 2c 20 | tc|_fsubr, |
|000042d0| 75 6e 6c 65 73 73 29 3b | 0a 20 20 72 65 74 75 72 |unless);|. retur|
|000042e0| 6e 20 55 4e 44 45 46 49 | 4e 45 44 3b 0a 7d 0a 5c |n UNDEFI|NED;.}.\|
|000042f0| 65 6e 64 7b 76 65 72 62 | 61 74 69 6d 7d 0a 5c 65 |end{verb|atim}.\e|
|00004300| 6e 64 7b 71 75 6f 74 65 | 7d 0a 7b 5c 63 61 70 74 |nd{quote|}.{\capt|
|00004310| 69 6f 6e 7b 53 6f 75 72 | 63 65 20 6c 69 73 74 69 |ion{Sour|ce listi|
|00004320| 6e 67 20 6f 66 20 66 69 | 6c 65 20 7b 5c 74 74 20 |ng of fi|le {\tt |
|00004330| 77 68 65 6e 5c 5f 75 6e | 6c 65 73 73 2e 63 7d 7d |when\_un|less.c}}|
|00004340| 7d 0a 5c 6c 61 62 65 6c | 7b 77 68 65 6e 7d 0a 5c |}.\label|{when}.\|
|00004350| 76 73 6b 69 70 32 6d 6d | 5c 68 72 75 6c 65 5c 76 |vskip2mm|\hrule\v|
|00004360| 73 6b 69 70 33 6d 6d 0a | 5c 65 6e 64 7b 66 69 67 |skip3mm.|\end{fig|
|00004370| 75 72 65 7d 0a 0a 5c 73 | 75 62 73 65 63 74 69 6f |ure}..\s|ubsectio|
|00004380| 6e 7b 53 69 67 6e 61 6c | 69 6e 67 20 65 72 72 6f |n{Signal|ing erro|
|00004390| 72 73 7d 0a 46 6f 72 20 | 6e 6f 77 2c 20 6f 6e 6c |rs}.For |now, onl|
|000043a0| 79 20 6f 6e 65 20 66 75 | 6e 63 74 69 6f 6e 20 69 |y one fu|nction i|
|000043b0| 73 20 70 72 6f 76 69 64 | 65 64 20 74 6f 20 73 69 |s provid|ed to si|
|000043c0| 67 6e 61 6c 20 65 72 72 | 6f 72 73 3a 20 5c 49 6e |gnal err|ors: \In|
|000043d0| 64 65 78 74 74 7b 53 54 | 6b 5c 5f 65 72 72 7d 2e |dextt{ST|k\_err}.|
|000043e0| 20 54 68 69 73 0a 66 75 | 6e 63 74 69 6f 6e 20 74 | This.fu|nction t|
|000043f0| 61 6b 65 73 20 74 77 6f | 20 70 61 72 61 6d 65 74 |akes two| paramet|
|00004400| 65 72 73 3a 20 61 20 43 | 20 73 74 72 69 6e 67 20 |ers: a C| string |
|00004410| 77 68 69 63 68 20 63 6f | 6e 73 74 69 74 75 74 65 |which co|nstitute|
|00004420| 73 20 74 68 65 20 62 6f | 64 79 20 6f 66 20 74 68 |s the bo|dy of th|
|00004430| 65 0a 6d 65 73 73 61 67 | 65 20 61 6e 64 20 61 20 |e.messag|e and a |
|00004440| 53 63 68 65 6d 65 20 6f | 62 6a 65 63 74 20 28 61 |Scheme o|bject (a|
|00004450| 20 7b 5c 74 74 20 53 43 | 4d 7d 20 70 6f 69 6e 74 | {\tt SC|M} point|
|00004460| 65 72 29 20 64 65 73 69 | 67 6e 61 74 69 6e 67 20 |er) desi|gnating |
|00004470| 74 68 65 20 7b 5c 65 6d | 0a 65 72 72 6f 6e 65 6f |the {\em|.erroneo|
|00004480| 75 73 7d 20 6f 62 6a 65 | 63 74 2e 20 20 49 66 20 |us} obje|ct. If |
|00004490| 74 68 65 20 73 65 63 6f | 6e 64 20 61 72 67 75 6d |the seco|nd argum|
|000044a0| 65 6e 74 20 69 73 20 5c | 49 6e 64 65 78 74 74 7b |ent is \|Indextt{|
|000044b0| 4e 49 4c 7d 2c 20 69 74 | 20 77 69 6c 6c 20 6e 6f |NIL}, it| will no|
|000044c0| 74 20 62 65 0a 70 72 69 | 6e 74 65 64 2e 20 45 78 |t be.pri|nted. Ex|
|000044d0| 65 63 75 74 69 6f 6e 20 | 6f 66 20 74 68 65 20 66 |ecution |of the f|
|000044e0| 75 6e 63 74 69 6f 6e 20 | 7b 5c 74 74 20 53 54 6b |unction |{\tt STk|
|000044f0| 5c 5f 65 72 72 7d 20 6e | 65 76 65 72 20 72 65 74 |\_err} n|ever ret|
|00004500| 75 72 6e 73 2e 20 20 49 | 74 20 70 72 6f 76 6f 6b |urns. I|t provok|
|00004510| 65 73 20 61 0a 6a 75 6d | 70 20 61 74 20 74 68 65 |es a.jum|p at the|
|00004520| 20 73 74 61 72 74 20 6f | 66 20 74 68 65 20 74 6f | start o|f the to|
|00004530| 70 2d 6c 65 76 65 6c 20 | 6c 6f 6f 70 2e 20 48 65 |p-level |loop. He|
|00004540| 72 65 61 66 74 65 72 2c | 20 69 73 20 61 20 6e 65 |reafter,| is a ne|
|00004550| 77 20 69 6d 70 6c 65 6d | 65 6e 74 61 74 69 6f 6e |w implem|entation|
|00004560| 20 6f 66 0a 74 68 65 20 | 7b 5c 74 74 20 77 68 65 | of.the |{\tt whe|
|00004570| 6e 7d 20 66 75 6e 63 74 | 69 6f 6e 20 77 68 69 63 |n} funct|ion whic|
|00004580| 68 20 75 73 65 73 20 7b | 5c 74 74 20 53 54 6b 5c |h uses {|\tt STk\|
|00004590| 5f 65 72 72 7d 20 77 68 | 65 6e 20 67 69 76 65 6e |_err} wh|en given|
|000045a0| 20 61 6e 20 65 72 72 6f | 6e 65 6f 75 73 0a 61 72 | an erro|neous.ar|
|000045b0| 67 75 6d 65 6e 74 73 20 | 6c 69 73 74 2e 0a 5c 62 |guments |list..\b|
|000045c0| 65 67 69 6e 7b 43 6f 64 | 65 7d 0a 5c 62 65 67 69 |egin{Cod|e}.\begi|
|000045d0| 6e 7b 61 6c 6c 74 74 7d | 0a 73 74 61 74 69 63 20 |n{alltt}|.static |
|000045e0| 50 52 49 4d 49 54 49 56 | 45 20 77 68 65 6e 28 53 |PRIMITIV|E when(S|
|000045f0| 43 4d 20 6c 2c 20 53 43 | 4d 20 65 6e 76 2c 20 69 |CM l, SC|M env, i|
|00004600| 6e 74 20 61 72 67 63 6f | 75 6e 74 29 0a 5c 7b 0a |nt argco|unt).\{.|
|00004610| 20 20 53 43 4d 20 72 65 | 73 20 3d 20 55 4e 44 45 | SCM re|s = UNDE|
|00004620| 46 49 4e 45 44 3b 0a 0a | 20 20 73 77 69 74 63 68 |FINED;..| switch|
|00004630| 20 28 61 72 67 63 6f 75 | 6e 74 29 20 5c 7b 0a 20 | (argcou|nt) \{. |
|00004640| 20 20 20 63 61 73 65 20 | 30 3a 20 20 53 54 6b 5f | case |0: STk_|
|00004650| 65 72 72 28 22 77 68 65 | 6e 3a 20 6e 6f 20 61 72 |err("whe|n: no ar|
|00004660| 67 75 6d 65 6e 74 20 6c | 69 73 74 20 67 69 76 65 |gument l|ist give|
|00004670| 6e 22 2c 20 4e 49 4c 29 | 3b 0a 20 20 20 20 63 61 |n", NIL)|;. ca|
|00004680| 73 65 20 31 3a 20 20 53 | 54 6b 5f 65 72 72 28 22 |se 1: S|Tk_err("|
|00004690| 77 68 65 6e 3a 20 6e 75 | 6c 6c 20 62 6f 64 79 22 |when: nu|ll body"|
|000046a0| 2c 20 4e 49 4c 29 3b 0a | 20 20 20 20 64 65 66 61 |, NIL);.| defa|
|000046b0| 75 6c 74 3a 20 7b 5c 65 | 6d 20 2f 2a 20 41 72 67 |ult: {\e|m /* Arg|
|000046c0| 75 6d 65 6e 74 20 6c 69 | 73 74 20 69 73 20 77 65 |ument li|st is we|
|000046d0| 6c 6c 20 66 6f 72 6d 65 | 64 2e 0a 20 20 20 20 20 |ll forme|d.. |
|000046e0| 20 20 20 20 20 20 20 20 | 20 2a 20 45 76 61 6c 75 | | * Evalu|
|000046f0| 61 74 65 20 65 61 63 68 | 20 65 78 70 72 65 73 73 |ate each| express|
|00004700| 69 6f 6e 20 6f 66 20 74 | 68 65 20 62 6f 64 79 20 |ion of t|he body |
|00004710| 0a 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 2a |. | *|
|00004720| 2f 7d 0a 20 20 20 20 20 | 20 20 20 20 20 20 20 20 |/}. | |
|00004730| 69 66 20 28 53 54 6b 5f | 65 76 61 6c 28 43 41 52 |if (STk_|eval(CAR|
|00004740| 28 6c 29 2c 20 65 6e 76 | 29 20 21 3d 20 4e 74 72 |(l), env|) != Ntr|
|00004750| 75 74 68 29 0a 20 20 20 | 20 20 20 20 20 20 20 20 |uth). | |
|00004760| 20 20 20 20 66 6f 72 20 | 28 6c 20 3d 20 43 44 52 | for |(l = CDR|
|00004770| 28 6c 29 3b 20 21 4e 55 | 4c 4c 50 28 6c 29 3b 20 |(l); !NU|LLP(l); |
|00004780| 6c 20 3d 20 43 44 52 28 | 6c 29 29 20 0a 20 20 20 |l = CDR(|l)) . |
|00004790| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 72 65 | | re|
|000047a0| 73 20 3d 20 53 54 6b 5f | 65 76 61 6c 28 43 41 52 |s = STk_|eval(CAR|
|000047b0| 28 6c 29 2c 20 65 6e 76 | 29 3b 0a 20 20 5c 7d 0a |(l), env|);. \}.|
|000047c0| 20 20 72 65 74 75 72 6e | 20 72 65 73 3b 0a 5c 7d | return| res;.\}|
|000047d0| 0a 5c 65 6e 64 7b 61 6c | 6c 74 74 7d 0a 5c 65 6e |.\end{al|ltt}.\en|
|000047e0| 64 7b 43 6f 64 65 7d 0a | 0a 5c 73 65 63 74 69 6f |d{Code}.|.\sectio|
|000047f0| 6e 7b 56 61 72 69 61 62 | 6c 65 73 7d 0a 0a 54 68 |n{Variab|les}..Th|
|00004800| 69 73 20 73 65 63 74 69 | 6f 6e 20 73 68 6f 77 73 |is secti|on shows|
|00004810| 20 68 6f 77 20 79 6f 75 | 20 63 61 6e 20 61 63 63 | how you| can acc|
|00004820| 65 73 73 20 61 20 53 63 | 68 65 6d 65 20 76 61 72 |ess a Sc|heme var|
|00004830| 69 61 62 6c 65 20 77 69 | 74 68 69 6e 20 43 20 63 |iable wi|thin C c|
|00004840| 6f 64 65 2e 20 49 74 20 | 61 6c 73 6f 0a 73 68 6f |ode. It |also.sho|
|00004850| 77 73 20 68 6f 77 20 79 | 6f 75 20 63 61 6e 20 63 |ws how y|ou can c|
|00004860| 6f 6e 6e 65 63 74 20 61 | 20 53 63 68 65 6d 65 20 |onnect a| Scheme |
|00004870| 61 6e 64 20 43 20 76 61 | 72 69 61 62 6c 65 20 73 |and C va|riable s|
|00004880| 75 63 68 20 74 68 61 74 | 20 6d 6f 64 69 66 79 69 |uch that| modifyi|
|00004890| 6e 67 20 69 74 20 69 6e | 0a 53 63 68 65 6d 65 20 |ng it in|.Scheme |
|000048a0| 77 69 6c 6c 20 6d 6f 64 | 69 66 79 20 74 68 65 20 |will mod|ify the |
|000048b0| 61 73 73 6f 63 69 61 74 | 65 64 20 76 61 72 69 61 |associat|ed varia|
|000048c0| 62 6c 65 20 61 6e 64 20 | 7b 5c 65 6d 20 76 69 63 |ble and |{\em vic|
|000048d0| 65 20 76 65 72 73 61 7d | 2e 0a 0a 5c 73 75 62 73 |e versa}|...\subs|
|000048e0| 65 63 74 69 6f 6e 7b 53 | 63 68 65 6d 65 20 53 79 |ection{S|cheme Sy|
|000048f0| 6d 62 6f 6c 73 20 61 6e | 64 20 56 61 72 69 61 62 |mbols an|d Variab|
|00004900| 6c 65 73 7d 0a 0a 5c 62 | 65 67 69 6e 7b 4c 65 6e |les}..\b|egin{Len|
|00004910| 74 72 79 7d 0a 5c 69 74 | 65 6d 5b 44 65 66 69 6e |try}.\it|em[Defin|
|00004920| 69 6e 67 20 61 20 73 79 | 6d 62 6f 6c 5d 0a 49 6e |ing a sy|mbol].In|
|00004930| 74 65 72 6e 69 6e 67 20 | 61 20 73 79 6d 62 6f 6c |terning |a symbol|
|00004940| 20 69 6e 20 74 68 65 20 | 67 6c 6f 62 61 6c 20 74 | in the |global t|
|00004950| 61 62 6c 65 20 6f 66 20 | 73 79 6d 62 6f 6c 73 20 |able of |symbols |
|00004960| 69 73 20 64 6f 6e 65 20 | 77 69 74 68 20 74 68 65 |is done |with the|
|00004970| 0a 5c 49 6e 64 65 78 74 | 74 7b 53 54 6b 5c 5f 69 |.\Indext|t{STk\_i|
|00004980| 6e 74 65 72 6e 7d 20 43 | 20 66 75 6e 63 74 69 6f |ntern} C| functio|
|00004990| 6e 2e 20 53 69 6e 63 65 | 20 74 68 69 73 20 66 75 |n. Since| this fu|
|000049a0| 6e 63 74 69 6f 6e 20 69 | 73 20 6f 66 74 65 6e 20 |nction i|s often |
|000049b0| 75 73 65 64 2c 20 79 6f | 75 20 63 61 6e 20 75 73 |used, yo|u can us|
|000049c0| 65 0a 74 68 65 20 43 20 | 6d 61 63 72 6f 20 5c 49 |e.the C |macro \I|
|000049d0| 6e 64 65 78 74 74 7b 49 | 6e 74 65 72 6e 7d 20 61 |ndextt{I|ntern} a|
|000049e0| 73 20 61 20 73 68 6f 72 | 74 63 75 74 2e 20 54 68 |s a shor|tcut. Th|
|000049f0| 65 20 72 65 73 75 6c 74 | 20 6f 66 20 49 6e 74 65 |e result| of Inte|
|00004a00| 72 6e 20 69 73 20 74 68 | 65 20 7b 5c 74 74 20 53 |rn is th|e {\tt S|
|00004a10| 43 4d 7d 0a 6f 62 6a 65 | 63 74 20 77 68 69 63 68 |CM}.obje|ct which|
|00004a20| 20 64 65 6e 6f 74 65 73 | 20 74 68 65 20 73 63 68 | denotes| the sch|
|00004a30| 65 6d 65 20 73 79 6d 62 | 6f 6c 20 61 73 73 6f 63 |eme symb|ol assoc|
|00004a40| 69 61 74 65 64 20 74 6f | 20 74 68 65 20 43 20 73 |iated to| the C s|
|00004a50| 74 72 69 6e 67 20 70 61 | 73 73 65 64 20 61 73 20 |tring pa|ssed as |
|00004a60| 70 61 72 61 6d 65 74 65 | 72 2e 0a 46 6f 72 20 65 |paramete|r..For e|
|00004a70| 78 61 6d 70 6c 65 2c 20 | 61 73 73 69 67 6e 69 6e |xample, |assignin|
|00004a80| 67 20 74 68 65 20 6c 69 | 73 74 20 0a 5c 62 65 67 |g the li|st .\beg|
|00004a90| 69 6e 7b 43 6f 64 65 7d | 0a 5c 62 65 67 69 6e 7b |in{Code}|.\begin{|
|00004aa0| 6c 69 73 74 69 6e 67 7d | 5b 32 30 30 5d 7b 32 7d |listing}|[200]{2}|
|00004ab0| 0a 27 28 67 72 65 65 6e | 20 6f 72 61 6e 67 65 20 |.'(green| orange |
|00004ac0| 72 65 64 29 0a 5c 65 6e | 64 7b 6c 69 73 74 69 6e |red).\en|d{listin|
|00004ad0| 67 7d 0a 5c 65 6e 64 7b | 43 6f 64 65 7d 0a 74 6f |g}.\end{|Code}.to|
|00004ae0| 20 74 68 65 20 43 20 76 | 61 72 69 61 62 6c 65 20 | the C v|ariable |
|00004af0| 7b 5c 74 74 20 66 69 72 | 65 7d 20 63 61 6e 20 62 |{\tt fir|e} can b|
|00004b00| 65 20 64 6f 6e 65 20 62 | 79 0a 5c 62 65 67 69 6e |e done b|y.\begin|
|00004b10| 7b 43 6f 64 65 7d 0a 5c | 62 65 67 69 6e 7b 6c 69 |{Code}.\|begin{li|
|00004b20| 73 74 69 6e 67 7d 5b 32 | 30 30 5d 7b 32 7d 0a 53 |sting}[2|00]{2}.S|
|00004b30| 43 4d 20 66 69 72 65 20 | 3d 20 20 43 6f 6e 73 28 |CM fire |= Cons(|
|00004b40| 49 6e 74 65 72 6e 28 22 | 67 72 65 65 6e 22 29 2c |Intern("|green"),|
|00004b50| 0a 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 |. | |
|00004b60| 20 20 43 6f 6e 73 28 49 | 6e 74 65 72 6e 28 22 6f | Cons(I|ntern("o|
|00004b70| 72 61 6e 67 65 22 29 2c | 0a 20 20 20 20 20 20 20 |range"),|. |
|00004b80| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 43 | | C|
|00004b90| 6f 6e 73 28 49 6e 74 65 | 72 6e 28 22 72 65 64 22 |ons(Inte|rn("red"|
|00004ba0| 29 2c 20 4e 49 4c 29 29 | 29 3b 0a 5c 65 6e 64 7b |), NIL))|);.\end{|
|00004bb0| 6c 69 73 74 69 6e 67 7d | 0a 5c 65 6e 64 7b 43 6f |listing}|.\end{Co|
|00004bc0| 64 65 7d 0a 53 69 6e 63 | 65 20 74 68 69 73 20 6e |de}.Sinc|e this n|
|00004bd0| 6f 74 61 74 69 6f 6e 20 | 69 73 20 64 69 66 66 69 |otation |is diffi|
|00004be0| 63 75 6c 74 20 74 6f 20 | 72 65 61 64 2c 20 73 6f |cult to |read, so|
|00004bf0| 6d 65 20 6d 61 63 72 6f | 73 20 68 61 76 65 20 62 |me macro|s have b|
|00004c00| 65 65 6e 20 64 65 66 69 | 6e 65 64 20 69 6e 0a 5c |een defi|ned in.\|
|00004c10| 49 6e 64 65 78 74 74 7b | 53 72 63 2f 73 74 6b 2e |Indextt{|Src/stk.|
|00004c20| 68 7d 20 66 6f 72 20 62 | 75 69 6c 64 69 6e 67 20 |h} for b|uilding |
|00004c30| 6c 69 73 74 2e 20 54 68 | 65 73 65 20 6d 61 63 72 |list. Th|ese macr|
|00004c40| 6f 73 20 61 72 65 20 63 | 61 6c 6c 65 64 20 5c 49 |os are c|alled \I|
|00004c50| 6e 64 65 78 74 74 7b 4c | 49 53 54 78 7d 20 77 68 |ndextt{L|ISTx} wh|
|00004c60| 65 72 65 0a 78 20 69 73 | 20 61 20 6e 75 6d 62 65 |ere.x is| a numbe|
|00004c70| 72 20 28 63 6f 6d 70 72 | 69 73 65 64 20 62 65 74 |r (compr|ised bet|
|00004c80| 77 65 65 6e 20 31 20 61 | 6e 64 20 39 29 20 77 68 |ween 1 a|nd 9) wh|
|00004c90| 69 63 68 20 72 65 70 72 | 65 73 65 6e 74 20 74 68 |ich repr|esent th|
|00004ca0| 65 20 6c 65 6e 67 74 68 | 20 6f 66 20 74 68 65 20 |e length| of the |
|00004cb0| 6c 69 73 74 0a 74 6f 20 | 63 72 65 61 74 65 2e 20 |list.to |create. |
|00004cc0| 54 68 75 73 2c 20 74 68 | 65 20 70 72 65 76 69 6f |Thus, th|e previo|
|00004cd0| 75 73 20 65 78 61 6d 70 | 6c 65 20 63 6f 75 6c 64 |us examp|le could|
|00004ce0| 20 68 61 76 65 20 62 65 | 65 6e 20 77 72 69 74 74 | have be|en writt|
|00004cf0| 65 6e 20 61 73 20 0a 5c | 62 65 67 69 6e 7b 43 6f |en as .\|begin{Co|
|00004d00| 64 65 7d 0a 5c 62 65 67 | 69 6e 7b 6c 69 73 74 69 |de}.\beg|in{listi|
|00004d10| 6e 67 7d 5b 32 30 30 5d | 7b 32 7d 0a 53 43 4d 20 |ng}[200]|{2}.SCM |
|00004d20| 66 69 72 65 20 3d 20 20 | 4c 49 53 54 33 28 49 6e |fire = |LIST3(In|
|00004d30| 74 65 72 6e 28 22 67 72 | 65 65 6e 22 29 2c 20 49 |tern("gr|een"), I|
|00004d40| 6e 74 65 72 6e 28 22 6f | 72 61 6e 67 65 22 29 2c |ntern("o|range"),|
|00004d50| 20 49 6e 74 65 72 6e 28 | 22 72 65 64 22 29 29 3b | Intern(|"red"));|
|00004d60| 0a 5c 65 6e 64 7b 6c 69 | 73 74 69 6e 67 7d 0a 5c |.\end{li|sting}.\|
|00004d70| 65 6e 64 7b 43 6f 64 65 | 7d 0a 0a 5c 69 74 65 6d |end{Code|}..\item|
|00004d80| 5b 52 65 61 64 69 6e 67 | 20 61 20 76 61 72 69 61 |[Reading| a varia|
|00004d90| 62 6c 65 5d 0a 52 65 61 | 64 69 6e 67 20 61 20 76 |ble].Rea|ding a v|
|00004da0| 61 72 69 61 62 6c 65 20 | 69 6e 20 53 63 68 65 6d |ariable |in Schem|
|00004db0| 65 20 63 6f 72 72 65 73 | 70 6f 6e 64 73 20 69 6e |e corres|ponds in|
|00004dc0| 20 66 61 63 74 20 74 6f | 20 6c 6f 6f 6b 20 61 74 | fact to| look at|
|00004dd0| 20 74 68 65 20 76 61 6c | 75 65 20 61 73 73 6f 63 | the val|ue assoc|
|00004de0| 69 61 74 65 64 0a 74 6f | 20 61 20 73 79 6d 62 6f |iated.to| a symbo|
|00004df0| 6c 2e 20 54 68 65 20 76 | 61 6c 75 65 20 61 73 73 |l. The v|alue ass|
|00004e00| 6f 63 69 61 74 65 64 20 | 74 6f 20 61 20 73 79 6d |ociated |to a sym|
|00004e10| 62 6f 6c 20 63 61 6e 20 | 62 65 20 6f 62 74 61 69 |bol can |be obtai|
|00004e20| 6e 65 64 20 77 69 74 68 | 20 74 68 65 20 0a 5c 49 |ned with| the .\I|
|00004e30| 6e 64 65 78 74 74 7b 53 | 54 6b 5c 5f 67 65 74 5c |ndextt{S|Tk\_get\|
|00004e40| 5f 73 79 6d 62 6f 6c 5c | 5f 76 61 6c 75 65 7d 20 |_symbol\|_value} |
|00004e50| 43 20 6d 61 63 72 6f 2e | 20 54 68 69 73 20 6d 61 |C macro.| This ma|
|00004e60| 63 72 6f 20 72 65 74 75 | 72 6e 73 20 61 20 7b 5c |cro retu|rns a {\|
|00004e70| 74 74 20 53 43 4d 7d 20 | 6f 62 6a 65 63 74 0a 77 |tt SCM} |object.w|
|00004e80| 68 69 63 68 20 63 6f 72 | 72 65 73 70 6f 6e 64 20 |hich cor|respond |
|00004e90| 74 6f 20 74 68 65 20 76 | 61 6c 75 65 20 61 73 73 |to the v|alue ass|
|00004ea0| 6f 63 69 61 74 65 64 20 | 74 6f 20 74 68 65 20 73 |ociated |to the s|
|00004eb0| 79 6d 62 6f 6c 20 77 68 | 6f 73 65 20 6e 61 6d 65 |ymbol wh|ose name|
|00004ec0| 20 69 73 20 65 71 75 61 | 6c 20 74 6f 0a 74 68 65 | is equa|l to.the|
|00004ed0| 20 70 61 72 61 6d 65 74 | 65 72 20 73 74 72 69 6e | paramet|er strin|
|00004ee0| 67 2e 20 5c 49 6e 64 65 | 78 74 74 7b 53 54 6b 5c |g. \Inde|xtt{STk\|
|00004ef0| 5f 67 65 74 5c 5f 73 79 | 6d 62 6f 6c 5c 5f 76 61 |_get\_sy|mbol\_va|
|00004f00| 6c 75 65 7d 20 72 65 74 | 75 72 6e 73 20 74 68 65 |lue} ret|urns the|
|00004f10| 20 73 70 65 63 69 61 6c | 0a 76 61 6c 75 65 20 5c | special|.value \|
|00004f20| 49 6e 64 65 78 74 74 7b | 55 4e 42 4f 55 4e 44 7d |Indextt{|UNBOUND}|
|00004f30| 20 69 73 20 74 68 69 73 | 20 73 79 6d 62 6f 6c 73 | is this| symbols|
|00004f40| 20 68 61 73 20 6e 6f 20 | 76 61 6c 75 65 20 69 6e | has no |value in|
|00004f50| 20 74 68 65 20 67 6c 6f | 62 61 6c 0a 65 6e 76 69 | the glo|bal.envi|
|00004f60| 72 6f 6e 6d 65 6e 74 2e | 20 54 68 65 20 66 6f 6c |ronment.| The fol|
|00004f70| 6c 6f 77 69 6e 67 20 70 | 69 65 63 65 20 6f 66 20 |lowing p|iece of |
|00004f80| 63 6f 64 65 0a 5c 62 65 | 67 69 6e 7b 43 6f 64 65 |code.\be|gin{Code|
|00004f90| 7d 0a 5c 62 65 67 69 6e | 7b 6c 69 73 74 69 6e 67 |}.\begin|{listing|
|00004fa0| 7d 5b 32 30 30 5d 7b 32 | 7d 0a 7b 0a 20 20 53 43 |}[200]{2|}.{. SC|
|00004fb0| 4d 20 76 61 6c 20 3d 20 | 53 54 6b 5f 67 65 74 5f |M val = |STk_get_|
|00004fc0| 73 79 6d 62 6f 6c 5f 76 | 61 6c 75 65 28 22 66 6f |symbol_v|alue("fo|
|00004fd0| 6f 22 29 3b 0a 0a 20 20 | 69 66 20 28 76 61 6c 20 |o");.. |if (val |
|00004fe0| 3d 3d 20 55 4e 42 4f 55 | 4e 44 29 0a 20 20 20 20 |== UNBOU|ND). |
|00004ff0| 53 54 6b 5f 65 72 72 28 | 22 66 6f 6f 20 69 73 20 |STk_err(|"foo is |
|00005000| 75 6e 64 65 66 69 6e 65 | 64 22 2c 20 4e 49 4c 29 |undefine|d", NIL)|
|00005010| 3b 0a 20 20 65 6c 73 65 | 0a 20 20 20 20 53 54 6b |;. else|. STk|
|00005020| 5f 64 69 73 70 6c 61 79 | 28 76 61 6c 2c 20 55 4e |_display|(val, UN|
|00005030| 42 4f 55 4e 44 29 3b 0a | 7d 0a 5c 65 6e 64 7b 6c |BOUND);.|}.\end{l|
|00005040| 69 73 74 69 6e 67 7d 0a | 5c 65 6e 64 7b 43 6f 64 |isting}.|\end{Cod|
|00005050| 65 7d 0a 64 69 73 70 6c | 61 79 73 20 74 68 65 20 |e}.displ|ays the |
|00005060| 76 61 6c 75 65 20 6f 66 | 20 74 68 65 20 7b 5c 74 |value of| the {\t|
|00005070| 74 20 66 6f 6f 7d 20 73 | 79 6d 62 6f 6c 2c 20 6f |t foo} s|ymbol, o|
|00005080| 72 20 61 20 6d 65 73 73 | 61 67 65 20 69 73 20 7b |r a mess|age is {|
|00005090| 5c 74 74 20 66 6f 6f 7d | 20 69 73 20 75 6e 64 65 |\tt foo}| is unde|
|000050a0| 66 69 6e 65 64 20 69 6e | 20 74 68 65 0a 67 6c 6f |fined in| the.glo|
|000050b0| 62 61 6c 20 65 6e 76 69 | 72 6f 6e 6d 65 6e 74 2e |bal envi|ronment.|
|000050c0| 20 4e 6f 74 65 20 74 68 | 65 20 75 73 65 20 6f 66 | Note th|e use of|
|000050d0| 20 74 68 65 20 5c 49 6e | 64 65 78 74 74 7b 53 54 | the \In|dextt{ST|
|000050e0| 6b 5c 5f 64 69 73 70 6c | 61 79 7d 20 66 75 6e 63 |k\_displ|ay} func|
|000050f0| 74 69 6f 6e 20 77 68 69 | 63 68 0a 69 6d 70 6c 65 |tion whi|ch.imple|
|00005100| 6d 65 6e 74 20 74 68 65 | 20 62 65 68 61 76 69 6f |ment the| behavio|
|00005110| 72 20 6f 66 20 74 68 65 | 20 53 63 68 65 6d 65 20 |r of the| Scheme |
|00005120| 7b 5c 74 74 20 64 69 73 | 70 6c 61 79 7d 20 70 72 |{\tt dis|play} pr|
|00005130| 69 6d 69 74 69 76 65 2e | 20 54 68 69 73 20 63 61 |imitive.| This ca|
|00005140| 6c 6c 20 63 6f 72 72 65 | 73 70 6f 6e 64 20 74 6f |ll corre|spond to|
|00005150| 0a 61 20 63 61 6c 6c 20 | 74 6f 20 7b 5c 74 74 20 |.a call |to {\tt |
|00005160| 64 69 73 70 6c 61 79 7d | 20 77 69 74 68 20 6f 6e |display}| with on|
|00005170| 6c 79 20 6f 6e 65 20 70 | 61 72 61 6d 65 74 65 72 |ly one p|arameter|
|00005180| 2c 20 73 69 6e 63 65 20 | 73 65 63 6f 6e 64 20 70 |, since |second p|
|00005190| 61 72 61 6d 65 74 65 72 | 20 69 73 20 73 65 74 0a |arameter| is set.|
|000051a0| 74 6f 20 7b 5c 74 74 20 | 55 4e 42 4f 55 4e 44 7d |to {\tt |UNBOUND}|
|000051b0| 20 28 6f 75 74 70 75 74 | 20 69 73 20 64 6f 6e 65 | (output| is done|
|000051c0| 20 6f 6e 20 74 68 65 20 | 73 74 61 6e 64 61 72 64 | on the |standard|
|000051d0| 20 6f 75 74 70 75 74 20 | 70 6f 72 74 20 69 6e 20 | output |port in |
|000051e0| 74 68 69 73 20 63 61 73 | 65 29 2e 0a 0a 5c 69 74 |this cas|e)...\it|
|000051f0| 65 6d 5b 53 65 74 74 69 | 6e 67 20 61 20 76 61 72 |em[Setti|ng a var|
|00005200| 69 61 62 6c 65 5d 0a 53 | 65 74 74 69 6e 67 20 61 |iable].S|etting a|
|00005210| 20 53 63 68 65 6d 65 20 | 76 61 72 69 61 62 6c 65 | Scheme |variable|
|00005220| 20 63 6f 72 72 65 73 70 | 6f 6e 64 73 20 74 6f 20 | corresp|onds to |
|00005230| 61 73 73 6f 63 69 61 74 | 65 20 61 20 6e 65 77 20 |associat|e a new |
|00005240| 76 61 6c 75 65 20 74 6f | 20 61 20 73 79 6d 62 6f |value to| a symbo|
|00005250| 6c 2e 20 54 68 65 0a 76 | 61 6c 75 65 20 6f 66 20 |l. The.v|alue of |
|00005260| 61 20 73 79 6d 62 6f 6c | 20 63 61 6e 20 62 65 20 |a symbol| can be |
|00005270| 73 65 74 20 77 69 74 68 | 20 74 68 65 20 5c 49 6e |set with| the \In|
|00005280| 64 65 78 74 74 7b 53 54 | 6b 5c 5f 73 65 74 5c 5f |dextt{ST|k\_set\_|
|00005290| 73 79 6d 62 6f 6c 5c 5f | 76 61 6c 75 65 7d 20 43 |symbol\_|value} C|
|000052a0| 20 6d 61 63 72 6f 2e 0a | 46 6f 72 20 65 78 61 6d | macro..|For exam|
|000052b0| 70 6c 65 2c 20 0a 5c 62 | 65 67 69 6e 7b 43 6f 64 |ple, .\b|egin{Cod|
|000052c0| 65 7d 0a 5c 62 65 67 69 | 6e 7b 6c 69 73 74 69 6e |e}.\begi|n{listin|
|000052d0| 67 7d 5b 32 30 30 5d 7b | 32 7d 0a 53 54 6b 5f 73 |g}[200]{|2}.STk_s|
|000052e0| 65 74 5f 73 79 6d 62 6f | 6c 5f 76 61 6c 75 65 28 |et_symbo|l_value(|
|000052f0| 22 62 61 72 22 2c 20 53 | 54 6b 5f 6d 61 6b 65 69 |"bar", S|Tk_makei|
|00005300| 6e 74 65 67 65 72 28 33 | 4c 29 29 3b 0a 5c 65 6e |nteger(3|L));.\en|
|00005310| 64 7b 6c 69 73 74 69 6e | 67 7d 0a 5c 65 6e 64 7b |d{listin|g}.\end{|
|00005320| 43 6f 64 65 7d 0a 73 65 | 74 73 20 74 68 65 20 76 |Code}.se|ts the v|
|00005330| 61 6c 75 65 20 6f 66 20 | 74 68 65 20 7b 5c 74 74 |alue of |the {\tt|
|00005340| 20 62 61 72 7d 20 73 79 | 6d 62 6f 6c 20 74 6f 20 | bar} sy|mbol to |
|00005350| 74 68 65 20 69 6e 74 65 | 67 65 72 20 33 2e 20 4e |the inte|ger 3. N|
|00005360| 6f 74 65 20 74 68 61 74 | 20 79 6f 75 20 63 61 6e |ote that| you can|
|00005370| 20 73 65 74 20 61 0a 73 | 79 6d 62 6f 6c 20 69 6e | set a.s|ymbol in|
|00005380| 20 43 20 77 69 74 68 6f | 75 74 20 75 73 69 6e 67 | C witho|ut using|
|00005390| 20 61 20 7b 5c 74 74 20 | 64 65 66 69 6e 65 7d 20 | a {\tt |define} |
|000053a0| 66 6f 72 6d 20 61 73 20 | 69 74 20 69 73 20 6e 65 |form as |it is ne|
|000053b0| 63 65 73 73 61 72 79 20 | 69 6e 20 53 63 68 65 6d |cessary |in Schem|
|000053c0| 65 2e 0a 5c 65 6e 64 7b | 4c 65 6e 74 72 79 7d 0a |e..\end{|Lentry}.|
|000053d0| 0a 5c 73 75 62 73 65 63 | 74 69 6f 6e 7b 43 6f 6e |.\subsec|tion{Con|
|000053e0| 6e 65 63 74 69 6e 67 20 | 53 63 68 65 6d 65 20 61 |necting |Scheme a|
|000053f0| 6e 64 20 43 20 76 61 72 | 69 61 62 6c 65 73 7d 0a |nd C var|iables}.|
|00005400| 0a 57 68 65 6e 20 62 75 | 69 6c 64 69 6e 67 20 61 |.When bu|ilding a|
|00005410| 20 73 70 65 63 69 61 6c | 69 7a 65 64 20 69 6e 74 | special|ized int|
|00005420| 65 72 70 72 65 74 65 72 | 2c 20 69 74 20 63 6f 75 |erpreter|, it cou|
|00005430| 6c 64 20 62 65 20 75 73 | 65 66 75 6c 20 74 6f 20 |ld be us|eful to |
|00005440| 68 61 76 65 20 61 20 76 | 61 72 69 61 62 6c 65 0a |have a v|ariable.|
|00005450| 79 6f 75 20 63 61 6e 20 | 61 63 63 65 73 73 20 62 |you can |access b|
|00005460| 6f 74 68 20 69 6e 20 53 | 63 68 65 6d 65 20 61 6e |oth in S|cheme an|
|00005470| 20 69 6e 20 43 2e 20 4d | 6f 64 69 66 79 69 6e 67 | in C. M|odifying|
|00005480| 20 73 75 63 68 20 61 20 | 76 61 72 69 61 62 6c 65 | such a |variable|
|00005490| 20 69 6e 20 43 20 6d 75 | 73 74 0a 6d 6f 64 69 66 | in C mu|st.modif|
|000054a0| 79 20 74 68 65 20 53 63 | 68 65 6d 65 20 61 73 73 |y the Sc|heme ass|
|000054b0| 6f 63 69 61 74 65 64 20 | 76 61 72 69 61 62 6c 65 |ociated |variable|
|000054c0| 20 61 6e 64 2c 20 73 79 | 6d 6d 65 74 72 69 63 61 | and, sy|mmetrica|
|000054d0| 6c 6c 79 2c 20 6d 6f 64 | 69 66 79 69 6e 67 20 69 |lly, mod|ifying i|
|000054e0| 74 20 69 6e 20 53 63 68 | 65 6d 65 0a 6d 75 73 74 |t in Sch|eme.must|
|000054f0| 20 6d 6f 64 69 66 79 20 | 74 68 65 20 63 6f 72 72 | modify |the corr|
|00005500| 65 73 70 6f 6e 64 69 6e | 67 20 43 20 76 61 72 69 |espondin|g C vari|
|00005510| 61 62 6c 65 2e 20 4f 6e | 65 20 77 61 79 20 74 6f |able. On|e way to|
|00005520| 20 64 6f 20 74 68 69 73 | 20 63 6f 6e 6e 65 63 74 | do this| connect|
|00005530| 69 6f 6e 20 63 6f 6e 73 | 69 73 74 73 0a 74 6f 20 |ion cons|ists.to |
|00005540| 63 72 65 61 74 65 20 61 | 20 73 70 65 63 69 61 6c |create a| special|
|00005550| 20 53 63 68 65 6d 65 20 | 76 61 72 69 61 62 6c 65 | Scheme |variable|
|00005560| 20 77 68 6f 73 65 20 63 | 6f 6e 74 65 6e 74 20 69 | whose c|ontent i|
|00005570| 73 20 72 65 61 64 2f 77 | 72 69 74 74 65 6e 20 62 |s read/w|ritten b|
|00005580| 79 20 61 20 73 70 65 63 | 69 61 6c 0a 67 65 74 74 |y a spec|ial.gett|
|00005590| 65 72 2f 73 65 74 74 65 | 72 2e 20 44 65 66 69 6e |er/sette|r. Defin|
|000055a0| 69 74 69 6f 6e 20 6f 66 | 20 73 75 63 68 20 61 20 |ition of| such a |
|000055b0| 76 61 72 69 61 62 6c 65 | 2c 20 69 73 20 64 6f 6e |variable|, is don|
|000055c0| 65 20 62 79 20 63 61 6c | 6c 69 6e 67 20 74 68 65 |e by cal|ling the|
|000055d0| 20 66 75 6e 63 74 69 6f | 6e 0a 5c 49 6e 64 65 78 | functio|n.\Index|
|000055e0| 74 74 7b 53 54 6b 5c 5f | 64 65 66 69 6e 65 5c 5f |tt{STk\_|define\_|
|000055f0| 43 5c 5f 76 61 72 69 61 | 62 6c 65 7d 2e 20 54 68 |C\_varia|ble}. Th|
|00005600| 65 20 43 20 70 72 6f 74 | 6f 74 79 70 65 20 66 6f |e C prot|otype fo|
|00005610| 72 20 74 68 69 73 20 66 | 75 6e 63 74 69 6f 6e 20 |r this f|unction |
|00005620| 69 73 0a 5c 62 65 67 69 | 6e 7b 43 6f 64 65 7d 0a |is.\begi|n{Code}.|
|00005630| 5c 62 65 67 69 6e 7b 6c | 69 73 74 69 6e 67 7d 5b |\begin{l|isting}[|
|00005640| 32 30 30 5d 7b 32 7d 0a | 76 6f 69 64 20 53 54 6b |200]{2}.|void STk|
|00005650| 5f 64 65 66 69 6e 65 5f | 43 5f 76 61 72 69 61 62 |_define_|C_variab|
|00005660| 6c 65 28 63 68 61 72 20 | 2a 76 61 72 2c 20 0a 20 |le(char |*var, . |
|00005670| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|00005680| 20 20 20 20 20 20 20 20 | 20 20 53 43 4d 20 20 28 | | SCM (|
|00005690| 2a 67 65 74 74 65 72 29 | 28 63 68 61 72 20 2a 76 |*getter)|(char *v|
|000056a0| 61 72 29 2c 20 0a 20 20 | 20 20 20 20 20 20 20 20 |ar), . | |
|000056b0| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|000056c0| 20 76 6f 69 64 20 28 2a | 73 65 74 74 65 72 29 28 | void (*|setter)(|
|000056d0| 63 68 61 72 20 2a 76 61 | 72 2c 20 53 43 4d 20 76 |char *va|r, SCM v|
|000056e0| 61 6c 75 65 29 29 3b 0a | 5c 65 6e 64 7b 6c 69 73 |alue));.|\end{lis|
|000056f0| 74 69 6e 67 7d 0a 5c 65 | 6e 64 7b 43 6f 64 65 7d |ting}.\e|nd{Code}|
|00005700| 0a 0a 54 68 65 20 66 6f | 6c 6c 6f 77 69 6e 67 20 |..The fo|llowing |
|00005710| 70 69 65 63 65 20 6f 66 | 20 63 6f 64 65 20 73 68 |piece of| code sh|
|00005720| 6f 77 73 20 68 6f 77 20 | 77 65 20 63 61 6e 20 63 |ows how |we can c|
|00005730| 6f 6e 6e 65 63 74 20 74 | 68 65 20 53 63 68 65 6d |onnect t|he Schem|
|00005740| 65 20 76 61 72 69 61 62 | 6c 65 20 7b 5c 74 74 20 |e variab|le {\tt |
|00005750| 2a 65 72 72 6e 6f 2a 7d | 20 74 6f 20 74 68 65 20 |*errno*}| to the |
|00005760| 43 0a 76 61 72 69 61 62 | 6c 65 20 7b 5c 74 74 20 |C.variab|le {\tt |
|00005770| 65 72 72 6e 6f 7d 3a 0a | 0a 5c 62 65 67 69 6e 7b |errno}:.|.\begin{|
|00005780| 43 6f 64 65 7d 0a 5c 62 | 65 67 69 6e 7b 6c 69 73 |Code}.\b|egin{lis|
|00005790| 74 69 6e 67 7d 5b 32 30 | 30 5d 7b 32 7d 0a 73 74 |ting}[20|0]{2}.st|
|000057a0| 61 74 69 63 20 53 43 4d | 20 67 65 74 5f 65 72 72 |atic SCM| get_err|
|000057b0| 6e 6f 28 63 68 61 72 20 | 2a 73 29 0a 7b 0a 20 20 |no(char |*s).{. |
|000057c0| 72 65 74 75 72 6e 20 53 | 54 6b 5f 6d 61 6b 65 69 |return S|Tk_makei|
|000057d0| 6e 74 65 67 65 72 28 28 | 6c 6f 6e 67 29 20 65 72 |nteger((|long) er|
|000057e0| 72 6e 6f 29 3b 0a 7d 0a | 5c 65 6e 64 7b 6c 69 73 |rno);.}.|\end{lis|
|000057f0| 74 69 6e 67 7d 0a 5c 65 | 6e 64 7b 43 6f 64 65 7d |ting}.\e|nd{Code}|
|00005800| 0a 5c 62 65 67 69 6e 7b | 43 6f 64 65 7d 0a 5c 62 |.\begin{|Code}.\b|
|00005810| 65 67 69 6e 7b 6c 69 73 | 74 69 6e 67 7d 5b 32 30 |egin{lis|ting}[20|
|00005820| 30 5d 7b 32 7d 0a 73 74 | 61 74 69 63 20 76 6f 69 |0]{2}.st|atic voi|
|00005830| 64 20 73 65 74 5f 65 72 | 72 6e 6f 28 63 68 61 72 |d set_er|rno(char|
|00005840| 20 2a 73 2c 20 53 43 4d | 20 76 61 6c 75 65 29 0a | *s, SCM| value).|
|00005850| 7b 0a 20 20 6c 6f 6e 67 | 20 6e 20 3d 20 53 54 6b |{. long| n = STk|
|00005860| 5f 69 6e 74 65 67 65 72 | 5f 76 61 6c 75 65 5f 6e |_integer|_value_n|
|00005870| 6f 5f 6f 76 65 72 66 6c | 6f 77 28 76 61 6c 75 65 |o_overfl|ow(value|
|00005880| 29 3b 0a 0a 20 20 69 66 | 20 28 6e 20 3d 3d 20 4c |);.. if| (n == L|
|00005890| 4f 4e 47 5f 4d 49 4e 29 | 20 45 72 72 28 22 73 65 |ONG_MIN)| Err("se|
|000058a0| 74 74 69 6e 67 20 2a 65 | 72 72 6e 6f 2a 3a 20 62 |tting *e|rrno*: b|
|000058b0| 61 64 20 69 6e 74 65 67 | 65 72 22 2c 20 76 61 6c |ad integ|er", val|
|000058c0| 75 65 29 3b 0a 20 20 65 | 72 72 6e 6f 20 3d 20 6e |ue);. e|rrno = n|
|000058d0| 3b 0a 7d 0a 5c 65 6e 64 | 7b 6c 69 73 74 69 6e 67 |;.}.\end|{listing|
|000058e0| 7d 0a 5c 65 6e 64 7b 43 | 6f 64 65 7d 0a 5c 62 65 |}.\end{C|ode}.\be|
|000058f0| 67 69 6e 7b 43 6f 64 65 | 7d 0a 5c 62 65 67 69 6e |gin{Code|}.\begin|
|00005900| 7b 6c 69 73 74 69 6e 67 | 7d 5b 32 30 30 5d 7b 32 |{listing|}[200]{2|
|00005910| 7d 0a 7b 0a 20 20 2e 2e | 2e 0a 20 20 53 54 6b 5f |}.{. ..|.. STk_|
|00005920| 64 65 66 69 6e 65 5f 43 | 5f 76 61 72 69 61 62 6c |define_C|_variabl|
|00005930| 65 28 22 2a 65 72 72 6e | 6f 2a 22 2c 20 67 65 74 |e("*errn|o*", get|
|00005940| 5f 65 72 72 6e 6f 2c 20 | 73 65 74 5f 65 72 72 6e |_errno, |set_errn|
|00005950| 6f 29 3b 0a 20 20 2e 2e | 2e 0a 7d 0a 5c 65 6e 64 |o);. ..|..}.\end|
|00005960| 7b 6c 69 73 74 69 6e 67 | 7d 0a 5c 65 6e 64 7b 43 |{listing|}.\end{C|
|00005970| 6f 64 65 7d 0a 0a 41 66 | 74 65 72 20 74 68 69 73 |ode}..Af|ter this|
|00005980| 20 63 61 6c 6c 20 74 6f | 20 7b 5c 74 74 20 53 54 | call to| {\tt ST|
|00005990| 6b 5c 5f 64 65 66 69 6e | 65 5c 5f 43 5c 5f 76 61 |k\_defin|e\_C\_va|
|000059a0| 72 69 61 62 6c 65 7d 2c | 20 72 65 61 64 69 6e 67 |riable},| reading|
|000059b0| 20 28 7b 5c 65 6d 0a 72 | 65 73 70 7d 2e 20 77 72 | ({\em.r|esp}. wr|
|000059c0| 69 74 69 6e 67 29 20 74 | 68 65 20 76 61 6c 75 65 |iting) t|he value|
|000059d0| 20 6f 66 20 74 68 65 20 | 7b 5c 74 74 20 2a 65 72 | of the |{\tt *er|
|000059e0| 72 6e 6f 2a 7d 20 53 63 | 68 65 6d 65 20 76 61 72 |rno*} Sc|heme var|
|000059f0| 69 61 62 6c 65 20 63 61 | 6c 6c 73 20 74 68 65 0a |iable ca|lls the.|
|00005a00| 7b 5c 74 74 20 67 65 74 | 5c 5f 65 72 72 6e 6f 7d |{\tt get|\_errno}|
|00005a10| 20 28 7b 5c 65 6d 20 72 | 65 73 70 7d 2e 20 7b 5c | ({\em r|esp}. {\|
|00005a20| 74 74 20 73 65 74 5c 5f | 65 72 72 6e 6f 7d 29 20 |tt set\_|errno}) |
|00005a30| 43 20 66 75 6e 63 74 69 | 6f 6e 2e 0a 0a 5c 73 65 |C functi|on...\se|
|00005a40| 63 74 69 6f 6e 7b 43 61 | 6c 6c 69 6e 67 20 53 63 |ction{Ca|lling Sc|
|00005a50| 68 65 6d 65 20 66 72 6f | 6d 20 43 7d 0a 0a 53 6f |heme fro|m C}..So|
|00005a60| 6d 65 74 69 6d 65 73 2c | 20 69 74 20 63 6f 75 6c |metimes,| it coul|
|00005a70| 64 20 62 65 20 6e 65 63 | 65 73 73 61 72 79 20 74 |d be nec|essary t|
|00005a80| 6f 20 65 78 65 63 75 74 | 65 20 73 6f 6d 65 20 53 |o execut|e some S|
|00005a90| 63 68 65 6d 65 20 63 6f | 64 65 20 66 72 6f 6d 20 |cheme co|de from |
|00005aa0| 61 20 43 20 66 75 6e 63 | 74 69 6f 6e 2e 0a 49 66 |a C func|tion..If|
|00005ab0| 20 74 68 65 20 53 63 68 | 65 6d 65 20 66 75 6e 63 | the Sch|eme func|
|00005ac0| 74 69 6f 6e 20 79 6f 75 | 20 68 61 76 65 20 74 6f |tion you| have to|
|00005ad0| 20 63 61 6c 6c 20 69 73 | 20 61 20 70 72 69 6d 69 | call is| a primi|
|00005ae0| 74 69 76 65 2c 20 69 74 | 20 69 73 20 70 72 65 66 |tive, it| is pref|
|00005af0| 65 72 72 65 64 20 74 6f | 20 63 61 6c 6c 0a 64 69 |erred to| call.di|
|00005b00| 72 65 63 74 6c 79 20 74 | 68 65 20 43 20 66 75 6e |rectly t|he C fun|
|00005b10| 63 74 69 6f 6e 20 77 68 | 69 63 68 20 69 6d 70 6c |ction wh|ich impl|
|00005b20| 65 6d 65 6e 74 20 69 74 | 2e 20 54 6f 20 6b 6e 6f |ement it|. To kno|
|00005b30| 77 20 74 68 65 20 6e 61 | 6d 65 20 6f 66 20 74 68 |w the na|me of th|
|00005b40| 65 20 43 20 66 75 6e 63 | 74 69 6f 6e 0a 77 68 69 |e C func|tion.whi|
|00005b50| 63 68 20 69 6d 70 6c 65 | 6d 65 6e 74 20 61 20 53 |ch imple|ment a S|
|00005b60| 63 68 65 6d 65 20 70 72 | 69 6d 69 74 69 76 65 2c |cheme pr|imitive,|
|00005b70| 20 79 6f 75 27 6c 6c 20 | 68 61 76 65 20 74 6f 20 | you'll |have to |
|00005b80| 6c 6f 6f 6b 20 69 6e 20 | 74 68 65 20 43 20 66 69 |look in |the C fi|
|00005b90| 6c 65 20 7b 5c 74 74 0a | 70 72 69 6d 69 74 69 76 |le {\tt.|primitiv|
|00005ba0| 65 5c 2e 63 7d 20 77 68 | 69 63 68 20 63 6f 6e 74 |e\.c} wh|ich cont|
|00005bb0| 61 69 6e 73 20 74 68 65 | 20 6c 69 73 74 20 6f 66 |ains the| list of|
|00005bc0| 20 61 6c 6c 20 74 68 65 | 20 70 72 69 6d 69 74 69 | all the| primiti|
|00005bd0| 76 65 73 20 6f 66 20 74 | 68 65 20 63 6f 72 65 0a |ves of t|he core.|
|00005be0| 69 6e 74 65 72 70 72 65 | 74 65 72 2e 20 49 66 20 |interpre|ter. If |
|00005bf0| 74 68 65 20 53 63 68 65 | 6d 65 20 63 6f 64 65 20 |the Sche|me code |
|00005c00| 79 6f 75 20 77 61 6e 74 | 20 74 6f 20 65 78 65 63 |you want| to exec|
|00005c10| 75 74 65 20 69 73 20 6e | 6f 74 20 61 20 63 61 6c |ute is n|ot a cal|
|00005c20| 6c 20 74 6f 20 61 0a 70 | 72 69 6d 69 74 69 76 65 |l to a.p|rimitive|
|00005c30| 2c 20 69 74 20 69 73 20 | 67 65 6e 65 72 61 6c 6c |, it is |generall|
|00005c40| 79 20 65 61 73 69 65 72 | 20 74 6f 20 70 75 74 20 |y easier| to put |
|00005c50| 79 6f 75 72 20 63 6f 64 | 65 20 69 6e 20 61 20 43 |your cod|e in a C|
|00005c60| 20 73 74 72 69 6e 67 20 | 61 6e 64 20 63 61 6c 6c | string |and call|
|00005c70| 20 74 68 65 20 43 0a 66 | 75 6e 63 74 69 6f 6e 20 | the C.f|unction |
|00005c80| 5c 49 6e 64 65 78 74 74 | 7b 53 54 6b 5c 5f 65 76 |\Indextt|{STk\_ev|
|00005c90| 61 6c 5c 5f 43 5c 5f 73 | 74 72 69 6e 67 7d 2e 20 |al\_C\_s|tring}. |
|00005ca0| 54 68 69 73 20 66 75 6e | 63 74 69 6f 6e 20 74 61 |This fun|ction ta|
|00005cb0| 6b 65 73 20 74 77 6f 20 | 70 61 72 61 6d 65 74 65 |kes two |paramete|
|00005cc0| 72 73 3a 20 74 68 65 20 | 73 74 72 69 6e 67 0a 74 |rs: the |string.t|
|00005cd0| 6f 20 65 76 61 6c 75 61 | 74 65 20 61 6e 64 20 74 |o evalua|te and t|
|00005ce0| 68 65 20 65 6e 76 69 72 | 6f 6e 6d 65 6e 74 20 69 |he envir|onment i|
|00005cf0| 6e 20 77 68 69 63 68 20 | 65 76 61 6c 75 61 74 69 |n which |evaluati|
|00005d00| 6f 6e 20 6d 75 73 74 20 | 74 61 6b 65 20 70 6c 61 |on must |take pla|
|00005d10| 63 65 2e 20 41 73 20 66 | 6f 72 20 7b 5c 74 74 0a |ce. As f|or {\tt.|
|00005d20| 53 54 6b 5c 5f 65 76 61 | 6c 7d 2c 20 61 20 5c 49 |STk\_eva|l}, a \I|
|00005d30| 6e 64 65 78 74 74 7b 4e | 49 4c 7d 20 76 61 6c 75 |ndextt{N|IL} valu|
|00005d40| 65 20 66 6f 72 20 74 68 | 65 20 65 6e 76 69 72 6f |e for th|e enviro|
|00005d50| 6e 6d 65 6e 74 20 64 65 | 6e 6f 74 65 73 20 74 68 |nment de|notes th|
|00005d60| 65 20 67 6c 6f 62 61 6c | 0a 65 6e 76 69 72 6f 6e |e global|.environ|
|00005d70| 6d 65 6e 74 2e 20 53 75 | 70 70 6f 73 65 2c 20 66 |ment. Su|ppose, f|
|00005d80| 6f 72 20 69 6e 73 74 61 | 6e 63 65 2c 20 74 68 61 |or insta|nce, tha|
|00005d90| 74 20 79 6f 75 20 68 61 | 76 65 20 61 6c 72 65 61 |t you ha|ve alrea|
|00005da0| 64 79 20 77 72 69 74 74 | 65 6e 20 69 6e 20 53 63 |dy writt|en in Sc|
|00005db0| 68 65 6d 65 20 74 68 65 | 0a 7b 5c 74 74 20 66 61 |heme the|.{\tt fa|
|00005dc0| 63 74 7d 20 70 72 6f 63 | 65 64 75 72 65 3b 20 65 |ct} proc|edure; e|
|00005dd0| 76 61 6c 75 61 74 69 6e | 67 20 74 68 65 20 66 61 |valuatin|g the fa|
|00005de0| 63 74 6f 72 69 61 6c 20 | 6f 66 20 31 30 20 63 61 |ctorial |of 10 ca|
|00005df0| 6e 20 62 65 20 64 6f 6e | 65 20 69 6e 20 43 20 77 |n be don|e in C w|
|00005e00| 69 74 68 3a 0a 5c 62 65 | 67 69 6e 7b 43 6f 64 65 |ith:.\be|gin{Code|
|00005e10| 7d 0a 5c 62 65 67 69 6e | 7b 6c 69 73 74 69 6e 67 |}.\begin|{listing|
|00005e20| 7d 5b 32 30 30 5d 7b 32 | 7d 0a 53 54 6b 5f 65 76 |}[200]{2|}.STk_ev|
|00005e30| 61 6c 5f 73 74 72 69 6e | 67 28 22 28 66 61 63 74 |al_strin|g("(fact|
|00005e40| 20 31 30 29 22 2c 20 4e | 49 4c 29 3b 0a 5c 65 6e | 10)", N|IL);.\en|
|00005e50| 64 7b 6c 69 73 74 69 6e | 67 7d 0a 5c 65 6e 64 7b |d{listin|g}.\end{|
|00005e60| 43 6f 64 65 7d 0a 54 68 | 69 73 20 63 61 6c 6c 20 |Code}.Th|is call |
|00005e70| 72 65 74 75 72 6e 73 20 | 61 20 70 6f 69 6e 74 65 |returns |a pointe|
|00005e80| 72 20 6f 6e 20 61 20 53 | 63 68 65 6d 65 20 6f 62 |r on a S|cheme ob|
|00005e90| 6a 65 63 74 20 28 61 20 | 7b 5c 74 74 20 53 43 4d |ject (a |{\tt SCM|
|00005ea0| 7d 20 70 6f 69 6e 74 65 | 72 29 20 63 6f 6e 74 61 |} pointe|r) conta|
|00005eb0| 69 6e 69 6e 67 0a 74 68 | 65 20 72 65 73 75 6c 74 |ining.th|e result|
|00005ec0| 20 6f 66 20 74 68 65 20 | 65 76 61 6c 75 61 74 69 | of the |evaluati|
|00005ed0| 6f 6e 2e 20 49 66 20 61 | 6e 20 65 72 72 6f 72 20 |on. If a|n error |
|00005ee0| 6f 63 63 75 72 73 20 64 | 75 72 69 6e 67 20 65 76 |occurs d|uring ev|
|00005ef0| 61 6c 75 61 74 69 6f 6e | 2e 20 49 74 20 69 73 0a |aluation|. It is.|
|00005f00| 73 69 67 6e 61 6c 65 64 | 20 74 6f 20 74 68 65 20 |signaled| to the |
|00005f10| 75 73 65 72 20 61 6e 64 | 20 74 68 65 20 63 6f 6e |user and| the con|
|00005f20| 73 74 61 6e 74 20 4e 55 | 4c 4c 20 69 73 20 72 65 |stant NU|LL is re|
|00005f30| 74 75 72 6e 65 64 20 62 | 79 20 7b 5c 74 74 20 53 |turned b|y {\tt S|
|00005f40| 54 6b 5c 5f 65 76 61 6c | 5c 5f 73 74 72 69 6e 67 |Tk\_eval|\_string|
|00005f50| 7d 2e 0a 0a 5c 73 65 63 | 74 69 6f 6e 7b 41 64 64 |}...\sec|tion{Add|
|00005f60| 69 6e 67 20 6e 65 77 20 | 74 79 70 65 73 7d 0a 0a |ing new |types}..|
|00005f70| 54 68 69 73 20 73 65 63 | 74 69 6f 6e 73 20 64 69 |This sec|tions di|
|00005f80| 73 63 75 73 73 65 73 20 | 68 6f 77 20 74 6f 20 61 |scusses |how to a|
|00005f90| 64 64 20 61 20 6e 65 77 | 20 74 79 70 65 20 74 6f |dd a new| type to|
|00005fa0| 20 74 68 65 20 7b 5c 73 | 74 6b 7d 20 69 6e 74 65 | the {\s|tk} inte|
|00005fb0| 72 70 72 65 74 65 72 2e | 20 49 6e 74 65 72 65 73 |rpreter.| Interes|
|00005fc0| 74 65 64 0a 72 65 61 64 | 65 72 20 63 61 6e 20 66 |ted.read|er can f|
|00005fd0| 69 6e 64 20 73 6f 6d 65 | 20 6e 65 77 20 74 79 70 |ind some| new typ|
|00005fe0| 65 73 20 64 65 66 69 6e | 69 74 69 6f 6e 73 20 69 |es defin|itions i|
|00005ff0| 6e 20 74 68 65 20 7b 5c | 74 74 20 45 78 74 65 6e |n the {\|tt Exten|
|00006000| 73 69 6f 6e 73 7d 20 64 | 69 72 65 63 74 6f 72 79 |sions} d|irectory|
|00006010| 20 6f 66 0a 53 54 6b 2e | 20 7b 5c 73 74 6b 6c 6f | of.STk.| {\stklo|
|00006020| 73 7d 2c 20 69 6e 20 70 | 61 72 74 69 63 75 6c 61 |s}, in p|articula|
|00006030| 72 2c 20 69 73 20 77 72 | 69 74 74 65 6e 20 61 73 |r, is wr|itten as|
|00006040| 20 61 6e 20 65 78 74 65 | 6e 64 65 64 20 74 79 70 | an exte|nded typ|
|00006050| 65 20 77 68 6f 73 65 20 | 64 65 66 69 6e 69 74 69 |e whose |definiti|
|00006060| 6f 6e 0a 69 73 20 64 79 | 6e 61 6d 69 63 61 6c 6c |on.is dy|namicall|
|00006070| 79 20 64 6f 6e 65 20 61 | 73 20 73 6f 6f 6e 20 61 |y done a|s soon a|
|00006080| 73 20 7b 5c 65 6d 20 6f | 62 6a 65 63 74 73 7d 20 |s {\em o|bjects} |
|00006090| 61 72 65 20 6e 65 65 64 | 65 64 2e 20 48 61 73 68 |are need|ed. Hash|
|000060a0| 20 74 61 62 6c 65 73 2c | 20 70 72 6f 63 65 73 73 | tables,| process|
|000060b0| 65 73 0a 61 6e 64 20 73 | 6f 63 6b 65 74 73 20 61 |es.and s|ockets a|
|000060c0| 72 65 20 6f 74 68 65 72 | 20 65 78 61 6d 70 6c 65 |re other| example|
|000060d0| 73 20 6f 66 20 65 78 74 | 65 6e 64 65 64 20 74 79 |s of ext|ended ty|
|000060e0| 70 65 73 2e 20 0a 0a 5c | 73 75 62 73 65 63 74 69 |pes. ..\|subsecti|
|000060f0| 6f 6e 7b 44 65 66 69 6e | 69 74 69 6f 6e 20 6f 66 |on{Defin|ition of|
|00006100| 20 61 20 53 63 68 65 6d | 65 20 65 78 74 65 6e 64 | a Schem|e extend|
|00006110| 65 64 20 74 79 70 65 7d | 0a 0a 44 65 66 69 6e 69 |ed type}|..Defini|
|00006120| 6e 67 20 61 20 73 63 68 | 65 6d 65 20 65 78 74 65 |ng a sch|eme exte|
|00006130| 6e 64 65 64 20 74 79 70 | 65 20 69 73 20 61 20 6c |nded typ|e is a l|
|00006140| 69 74 74 6c 65 20 62 69 | 74 20 6d 6f 72 65 20 63 |ittle bi|t more c|
|00006150| 6f 6d 70 6c 69 63 61 74 | 65 64 20 74 68 61 6e 0a |omplicat|ed than.|
|00006160| 64 65 66 69 6e 69 6e 67 | 20 6e 65 77 20 70 72 69 |defining| new pri|
|00006170| 6d 69 74 69 76 65 73 20 | 73 69 6e 63 65 20 69 74 |mitives |since it|
|00006180| 20 69 6d 70 6c 69 65 73 | 20 74 6f 20 74 61 6b 65 | implies| to take|
|00006190| 20 69 6e 74 6f 20 61 63 | 63 6f 75 6e 74 20 68 6f | into ac|count ho|
|000061a0| 77 20 74 68 69 73 0a 6e | 65 77 20 74 79 70 65 20 |w this.n|ew type |
|000061b0| 69 6e 74 65 72 61 63 74 | 20 77 69 74 68 20 74 68 |interact| with th|
|000061c0| 65 20 47 43 20 28 5c 49 | 6e 64 65 78 7b 47 61 72 |e GC (\I|ndex{Gar|
|000061d0| 62 61 67 65 20 43 6f 6c | 6c 65 63 74 6f 72 7d 29 |bage Col|lector})|
|000061e0| 2e 20 4e 6f 74 65 20 74 | 68 61 74 0a 75 6e 74 69 |. Note t|hat.unti|
|000061f0| 6c 20 6e 6f 77 20 77 65 | 20 68 61 76 65 20 6e 6f |l now we| have no|
|00006200| 74 20 64 69 73 63 75 73 | 73 65 64 20 61 62 6f 75 |t discus|sed abou|
|00006210| 74 20 47 43 20 70 72 6f | 62 6c 65 6d 73 20 73 69 |t GC pro|blems si|
|00006220| 6e 63 65 20 74 68 65 0a | 69 6e 74 65 72 70 72 65 |nce the.|interpre|
|00006230| 74 65 72 20 69 73 20 61 | 62 6c 65 20 74 6f 20 68 |ter is a|ble to h|
|00006240| 69 64 65 20 79 6f 75 20 | 69 74 2c 20 61 73 20 66 |ide you |it, as f|
|00006250| 61 72 20 61 73 20 79 6f | 75 20 64 6f 6e 27 74 20 |ar as yo|u don't |
|00006260| 64 65 66 69 6e 65 20 6e | 65 77 0a 74 79 70 65 73 |define n|ew.types|
|00006270| 2e 20 0a 0a 54 6f 20 69 | 6c 6c 75 73 74 72 61 74 |. ..To i|llustrat|
|00006280| 65 20 74 68 65 20 64 69 | 73 63 75 73 73 69 6f 6e |e the di|scussion|
|00006290| 2c 20 77 65 20 77 69 6c | 6c 20 73 68 6f 77 20 68 |, we wil|l show h|
|000062a0| 6f 77 20 74 6f 20 61 64 | 64 20 74 68 65 20 7b 5c |ow to ad|d the {\|
|000062b0| 65 6d 20 73 74 61 63 6b | 7d 0a 74 79 70 65 20 74 |em stack|}.type t|
|000062c0| 6f 20 74 68 65 20 7b 5c | 73 74 6b 7d 20 69 6e 74 |o the {\|stk} int|
|000062d0| 65 72 70 72 65 74 65 72 | 20 69 6e 20 74 68 69 73 |erpreter| in this|
|000062e0| 20 73 65 63 74 69 6f 6e | 2e 20 54 68 65 20 63 6f | section|. The co|
|000062f0| 6d 70 6c 65 74 65 20 63 | 6f 64 65 20 66 6f 72 0a |mplete c|ode for.|
|00006300| 74 68 69 73 20 73 65 63 | 74 69 6f 6e 20 63 61 6e |this sec|tion can|
|00006310| 20 62 65 20 66 6f 75 6e | 64 20 69 6e 20 61 70 70 | be foun|d in app|
|00006320| 65 6e 64 69 78 2e 5c 6c | 61 62 65 6c 7b 73 74 61 |endix.\l|abel{sta|
|00006330| 63 6b 7d 0a 0a 5c 73 75 | 62 73 75 62 73 65 63 74 |ck}..\su|bsubsect|
|00006340| 69 6f 6e 7b 48 6f 77 20 | 74 68 65 20 47 43 20 77 |ion{How |the GC w|
|00006350| 6f 72 6b 73 7d 0a 0a 42 | 65 66 6f 72 65 20 73 68 |orks}..B|efore sh|
|00006360| 6f 77 69 6e 67 20 68 6f | 77 20 74 6f 20 64 65 66 |owing ho|w to def|
|00006370| 69 6e 65 20 61 20 6e 65 | 77 20 53 63 68 65 6d 65 |ine a ne|w Scheme|
|00006380| 20 74 79 70 65 2c 20 69 | 74 20 69 73 20 69 6d 70 | type, i|t is imp|
|00006390| 6f 72 74 61 6e 74 20 74 | 6f 20 75 6e 64 65 72 73 |ortant t|o unders|
|000063a0| 74 61 6e 64 0a 68 6f 77 | 20 74 68 65 20 47 43 20 |tand.how| the GC |
|000063b0| 77 6f 72 6b 73 2e 20 46 | 69 72 73 74 20 61 20 63 |works. F|irst a c|
|000063c0| 65 72 74 61 69 6e 20 6e | 75 6d 62 65 72 20 6f 66 |ertain n|umber of|
|000063d0| 20 63 65 6c 6c 73 20 61 | 72 65 20 63 72 65 61 74 | cells a|re creat|
|000063e0| 65 64 5c 66 6f 6f 74 6e | 6f 74 65 7b 62 79 0a 64 |ed\footn|ote{by.d|
|000063f0| 65 66 61 75 6c 74 20 32 | 30 7e 30 30 30 3b 20 55 |efault 2|0~000; U|
+--------+-------------------------+-------------------------+--------+--------+
Only 25.0 KB of data is shown above.